summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2012-01-11 15:26:44 +0100
committerGravatar Nikias Bassen2012-01-11 15:26:44 +0100
commited4c858c5f37113f498fe6e85366ae38a0f29a9d (patch)
tree5574a89ede709508009aad6cadeef32450239045
parent567a749696a4a01d1eccc01e61dd2b1d76c39b5a (diff)
downloadlibplist-ed4c858c5f37113f498fe6e85366ae38a0f29a9d.tar.gz
libplist-ed4c858c5f37113f498fe6e85366ae38a0f29a9d.tar.bz2
node_list: Fix memory corruption
The corruption occured if you removed the last node from the list and later add a new node to the list.
-rw-r--r--libcnary/node_list.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/libcnary/node_list.c b/libcnary/node_list.c
index 2a9cf90..78f450e 100644
--- a/libcnary/node_list.c
+++ b/libcnary/node_list.c
@@ -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;
@@ -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