valgrind giving error but unable to find location

霸气de小男生 提交于 2019-12-06 03:55:15

This line:

==12885==    by 0x804A51D: main (sendip.c:575)

indicates that the leaked memory was allocated at line 575 of sendip.c (by a function called on that line, which subsequently called down to malloc()). You can't see the name of that function because whichever file it was in was not compiled with debugging info.


So the offending line is:

if(!mod->do_opt(opts[longindex].name,gnuoptarg,mod->pack)) {

This indicates that the memory leak is within the function mod->do_opt(). do_opt is a function pointer within the structure mod, so you will need to find the point where this value is set to go deeper.

There are can be several reasons of bad stack traces given by Memcheck tool. All of them are listed in Valgrind FAQ - 4.2. The stack traces given by Memcheck (or another tool) aren't helpful. How can I improve them?. In this case you are using dlopen and dlclose while working with shared libs and therefore most likely debug info was discarded after dlclose and Valgrind failed to produce good stack trace. Workaround is to avoid calling dlclose.

Also, for leak reports involving shared objects, if the shared object is unloaded before the program terminates, Valgrind will discard the debug information and the error message will be full of ??? entries. The workaround here is to avoid calling dlclose on these shared objects.

You should build your program and libraries with debug information (the -g option for gcc). If you don't, valgrind can still find the leaks but cannot point out where in your source code the errors come from. The ??? in the backtraces suggest that debug information is not available -- many of those should show function names and line numbers when debug info is present.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!