Skip to content

Commit

Permalink
node_list: Fix memory corruption
Browse files Browse the repository at this point in the history
The corruption occured if you removed the last node from the list
and later add a new node to the list.
  • Loading branch information
nikias committed Jan 11, 2012
1 parent e6f00ef commit 97731f8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion node_list.c
Expand Up @@ -59,7 +59,10 @@ int node_list_add(node_list_t* list, node_t* node) {
node->prev = last;

// Set the next element of our old "last" element
last->next = node;
if (last) {
// but only if the node list is not empty
last->next = node;
}

// Set the lists prev to the new last element
list->end = node;
Expand Down Expand Up @@ -129,6 +132,9 @@ int node_list_remove(node_list_t* list, node_t* node) {
node->prev->next = newnode;
if (newnode) {
newnode->prev = node->prev;
} else {
// last element in the list
list->end = node->prev;
}
} else {
// we just removed the first element
Expand Down

0 comments on commit 97731f8

Please sign in to comment.