From 9a1ba979b0bd349eb818b572c3b808cb54c10987 Mon Sep 17 00:00:00 2001 From: dmiller Date: Fri, 29 Jul 2022 15:21:14 +0000 Subject: [PATCH] Ensure gh_heap node addresses are NULL when invalid. --- nsock/src/gh_heap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nsock/src/gh_heap.c b/nsock/src/gh_heap.c index 3f759961c..ad0829e56 100644 --- a/nsock/src/gh_heap.c +++ b/nsock/src/gh_heap.c @@ -173,6 +173,7 @@ static int heap_grow(gh_heap_t *heap) { heap->slots = (gh_hnode_t **)safe_realloc(heap->slots, newsize * sizeof(gh_hnode_t *)); heap->highwm += GH_SLOTS; + memset(heap->slots + heap->count, 0, GH_SLOTS * sizeof(gh_hnode_t *)); return 0; } @@ -213,6 +214,7 @@ int gh_heap_push(gh_heap_t *heap, gh_hnode_t *hnode) { hnode->index = new_index; new_ptr = hnode_ptr(heap, new_index); + assert(*new_ptr == NULL); heap->count++; *new_ptr = hnode; @@ -245,5 +247,7 @@ int gh_heap_remove(gh_heap_t *heap, gh_hnode_t *hnode) } gh_hnode_invalidate(hnode); + cur_ptr = hnode_ptr(heap, count); + *cur_ptr = NULL; return 0; }