Reputation: 756
So, I'm at somewhat of a loss right now and hoping someone can help. I have a function defined in a library called 'list_free' which, as you can imagine, frees a list that you created earlier. When I call this function from within another module, my program segfaults. When running GDB though, I get:
(gdb) bt
#0 *__GI___libc_free (mem=0x65656853) at malloc.c:3709
#1 0x0804f279 in list_free ()
#2 0x0012ffef in set_var (...) at src/calc/model.c:337
#3 0x0804b320 in test_dependency_updates (_i=0) at src/tests/test_calc.c:63
#4 0x080507ea in srunner_run_all ()
#5 0x0804d2b9 in main () at src/tests/test_all.c:19
Thus, the line that caught my attention was #1 ... there is no reference to the source of that function. When I change the name of the function from list_free
to list_freex
(i.e., just something different) no more segfault. The other strange thing is if I change the name in the .c file, I get no warning of an "undefined reference to list_free" or whatever error I would get from forgetting to link in a library.
Thus, I'm led to believe that the function is being defined elsewhere, but I have no idea where. A grep -R list_free .
offers no help and the gdb output doesn't seem to indicate otherwise.
So I'm wondering if anyone has any tips on how to hunt down where this function might be defined. Also, I've renamed the function as noted above for now as I don't seem to have any other choice ... but I'm not sure if this is a good/safe idea? Ie, could I just be masking other problems by doing so?
Thanks in advance.
Upvotes: 1
Views: 873
Reputation: 108938
Try producing a link map from the linker.
On my system, to produce a map on stdout (lots and lots of lines)
gcc ... -Wl,-M ... ### ^ lowercase L
Or, to create a file with the map
gcc ... -Wl,-Map,a.map ...
Upvotes: 2
Reputation: 96266
If you are using linux, valgrind
is an invaluable tool to find problems with your memory management.
Upvotes: 7