fix invalid reads when removing linked list nodes default tip

Sat, 12 Oct 2024 19:41:04 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 12 Oct 2024 19:41:04 +0200
changeset 925
fd6e191f3268
parent 924
3c90dfc35f06

fix invalid reads when removing linked list nodes

src/linked_list.c file | annotate | diff | comparison | revisions
--- a/src/linked_list.c	Sat Oct 12 19:34:19 2024 +0200
+++ b/src/linked_list.c	Sat Oct 12 19:41:04 2024 +0200
@@ -776,11 +776,10 @@
             // element destruction
             cx_invoke_destructor(list, n->payload);
 
-            // free the node
+            // free the node and advance
+            void *next = n->next;
             cxFree(list->collection.allocator, n);
-
-            // next
-            n = n->next;
+            n = next;
         }
     } else {
         char *dest = targetbuf;
@@ -792,11 +791,10 @@
             // advance target buffer
             dest += list->collection.elem_size;
 
-            // free the node
+            // free the node and advance
+            void *next = n->next;
             cxFree(list->collection.allocator, n);
-
-            // next
-            n = n->next;
+            n = next;
         }
     }
 

mercurial