fixed ucx_list_remove crashing when removing the last element of a list

Thu, 10 Apr 2014 11:18:12 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 10 Apr 2014 11:18:12 +0200
changeset 161
1031dd910f8e
parent 160
302dddaf741d
child 162
52dfe5f4ecd7

fixed ucx_list_remove crashing when removing the last element of a list

ucx/list.c file | annotate | diff | comparison | revisions
--- a/ucx/list.c	Tue Mar 18 09:53:50 2014 +0100
+++ b/ucx/list.c	Thu Apr 10 11:18:12 2014 +0200
@@ -304,18 +304,18 @@
 }
     
 UcxList *ucx_list_remove_a(UcxAllocator *alloc, UcxList *l, UcxList *e) {
-    if (e->prev == NULL) {
-        if(e->next != NULL) {
-            e->next->prev = NULL;
-            l = e->next;
-        } else {
-            l = NULL;
-        }
-        
-    } else {
-        e->prev->next = e->next;
+    if (l == e) {
+        l = e->next;
+    }
+    
+    if (e->next) {
         e->next->prev = e->prev;
     }
+    
+    if (e->prev) {
+        e->prev->next = e->next;
+    }
+    
     alloc->free(alloc->pool, e);
     return l;
 }

mercurial