When the malloc call in hashmap_new succeeded but then the later calloc call failed, the error logic would call hashmap_free that would dereference m->data. This occurred because m->table_size is not yet set and likely contains a non-zero value, despite m->data == NULL. This change avoids the situation by zeroing the initial memory, including m->table_size.
When the
malloc
call inhashmap_new
succeeded but then the latercalloc
call failed, the error logic would callhashmap_free
that would dereferencem->data
. This occurred becausem->table_size
is not yet set and likely contains a non-zero value, despitem->data == NULL
. This change avoids the situation by zeroing the initial memory, includingm->table_size
.