mirror of
https://github.com/sigmasternchen/CFloor
synced 2025-03-15 04:18:55 +00:00
fixed a memory leak
This commit is contained in:
parent
08743ef960
commit
7dfa80572d
3 changed files with 13 additions and 5 deletions
3
Makefile
3
Makefile
|
@ -9,7 +9,8 @@ all: $(BIN_NAME)
|
|||
|
||||
test: obj/test.o obj/networking.o obj/linked.o
|
||||
$(LD) $(LDFLAGS) -o $@ $^
|
||||
valgrind: test
|
||||
valgrind: CFLAGS += -static -g
|
||||
valgrind: clean test
|
||||
valgrind --leak-check=yes ./test
|
||||
|
||||
obj/test.o: src/networking.h
|
||||
|
|
|
@ -73,18 +73,19 @@ void linked_free(link_t* link) {
|
|||
void linked_release(link_t* link) {
|
||||
link->inUse--;
|
||||
|
||||
if (link->unlinked && link->inUse == 0) {
|
||||
if (link->unlinked && (link->inUse == 0)) {
|
||||
linked_free(link);
|
||||
}
|
||||
}
|
||||
|
||||
link_t* linked_next(link_t* link) {
|
||||
link_t* next = link->next;
|
||||
linked_release(link);
|
||||
|
||||
if (link->next == NULL) {
|
||||
if (next == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
link = link->next;
|
||||
link = next;
|
||||
|
||||
link->inUse++;
|
||||
|
||||
|
@ -194,7 +195,7 @@ int linked_unlink(link_t* link) {
|
|||
}
|
||||
|
||||
void linked_destroy(linkedList_t* list) {
|
||||
link_t* link = linked_first(list);
|
||||
link_t* link = list->first;
|
||||
|
||||
while(link != NULL) {
|
||||
link_t* next = link->next;
|
||||
|
|
|
@ -75,6 +75,12 @@ void testLinkedList() {
|
|||
|
||||
checkInt(linked_length(&list), 2, "list length");
|
||||
|
||||
link = list.first;
|
||||
while(link != NULL) {
|
||||
checkInt(link->inUse, 0, "raw inUse");
|
||||
link = link->next;
|
||||
}
|
||||
|
||||
linked_destroy(&list);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue