Here, the memory is written to via memset before the check to ensure that the allocation succeeded. The second and third line should be switched, I think.
In _resize:
if (n_buckets > new_n_buckets) /* shrink the hash table */ \
h->keys = (khkey_t*)krealloc((void *)h->keys, new_n_buckets * sizeof(khkey_t)); \
Here, the pointer returned by krealloc is never checked (and if it's NULL, the original memory is also leaked).
There seems to be a few issues revolving around memory allocation.
In
_resize
:Here, the memory is written to via
memset
before the check to ensure that the allocation succeeded. The second and third line should be switched, I think.In
_resize
:Here, the pointer returned by
krealloc
is never checked (and if it'sNULL
, the original memory is also leaked).And in
_init
for the ensemble struct:Here, the memory for
g
is being written to without any check to make sure that the allocation succeeded.g->sub
is also never checked.