qhashtbl(0, QHASHTBL_THREADSAFE): double free or corruption (top): 0x0000000001d100b0 ***
allanwind opened this issue · 2 comments
allanwind commented
I modified examples/hashtbl.c as follows:
-
qhashtbl_t *tbl = qhashtbl(0, 0);
- qhashtbl_t *tbl = qhashtbl(0, QHASHTBL_THREADSAFE);
which then crashes with:
allan@vent:~/src/qlibc/examples$ ./hashtbl
*** Error in `./hashtbl': double free or corruption (top): 0x00000000015010b0 ***
Aborted
What am I missing?
refi64 commented
For some reason, this is returning true. Likely an issue with the mutex allocation code, because I can reproduce this, and I have plenty of memory left.
Now, when it jumps to malloc_failure
, it calls qhashtbl_free
. According to GDB, this is where the corruption occurs.
refi64 commented
Found it!
This line frees tbl->slots
, BUT it doesn't set it to NULL
. Two lines later, qhashtbl_free
is called, which frees it again.
This still doesn't explain why the malloc
failure is even occurring, though...