Hi everyone,
Sorry to trouble the list if this issue turns out to be spurious. I am
a relatively novice C programmer so it may just be my error. However,
I have implemented a program two ways: one using reallocarray() and
the other using calloc().
When I use reallocarray() I get the error "in realloc(): error: use
after free 0x..." So I recompiled with -g and ran gdb:
Program terminated with signal 6, Aborted.
Loaded symbols for /home/pmaddams/<REDACTED>
Reading symbols from /usr/lib/libutil.so.12.1...done.
Loaded symbols for /usr/lib/libutil.so.12.1
Reading symbols from /usr/lib/libc.so.84.2...done.
Loaded symbols for /usr/lib/libc.so.84.2
Reading symbols from /usr/libexec/ld.so...done.
Loaded symbols for /usr/libexec/ld.so
#0 0x00000c01badbc87a in thrkill () at <stdin>:2
2 <stdin>: No such file or directory.
in <stdin>
The situation is, I have a sorted array of at most 26 elements
representing the child nodes of a trie. Instead of using a linked list
I have opted to reallocate the array as a new pointer, shift the top
elements away from the insertion index, copy the new element into the
proper location, and assign the new pointer to the old variable.
Using small files this seems to work just fine. However, my goal is to
read in the entire file from /usr/share/dict/words, 2.4M of text. It
chokes and dies with the above error. But when I reimplement the
allocation routine with calloc() it seems to work fine.
What information can I provide to help confirm whether this is a bug
in the system, or in my own code?
Thanks.