Sat, 12 Oct 2024 19:41:04 +0200
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; } }