# HG changeset patch # User Mike Becker # Date 1757614212 -7200 # Node ID 37dcaeebe5cab9348a78b8e0f400350c55f497a0 # Parent 607f822c79fe53464a517bef53b6217e00e3104b kv-list: fix a possible source of UB when allocation fails during list creation relates to #461 diff -r 607f822c79fe -r 37dcaeebe5ca src/kv_list.c --- a/src/kv_list.c Thu Sep 11 20:09:33 2025 +0200 +++ b/src/kv_list.c Thu Sep 11 20:10:12 2025 +0200 @@ -357,9 +357,6 @@ // reallocate the list to add memory for storing the metadata cx_kv_list *kv_list = cxRealloc(allocator, list, sizeof(struct cx_kv_list_s)); - // zero the custom destructor information - memset((char*)kv_list + offsetof(cx_kv_list, list_destr), 0, sizeof(void*)*6); - // if any of the reallocations failed, we bail out if (kv_map != NULL && kv_list != NULL) { map = (CxMap*) kv_map; @@ -370,6 +367,9 @@ return NULL; } // LCOV_EXCL_STOP + // zero the custom destructor information + memset((char*)kv_list + offsetof(cx_kv_list, list_destr), 0, sizeof(void*)*6); + // combine the list and the map aspect kv_list->map = kv_map; kv_map->list = kv_list;