valgrind - Find memory leak in a shared library

前端 未结 2 1768
無奈伤痛
無奈伤痛 2021-02-19 23:43

I need to know ways to find out the memory leaks in a shared library which will be loaded to a release binary. I mean shared library I built with -g option but the binary that l

2条回答
  •  醉梦人生
    2021-02-20 00:34

    Assuming that the leak really is coming from your shared library then I don't think the problem is the lack of debugging in the main executable.

    More likely your problem is that the executable is unloading the shared library by calling dlclose before it finishes. That means that when valgrind comes to check for leaks all the symbol information for the library is gone as the library is no longer loaded.

    If you can rebuild the executable then the easiest solution may be to temporarily stop it calling dlclose so that the library stays loaded until the end.

    If you can't do that, then try using LD_PRELOAD to keep the library loaded, like this:

    LD_PRELOAD="/path/to/library.so" valgrind my-executable
    

    which will hopefully trick the dynamic linker into keeping the library loaded even after it has been closed.

提交回复
热议问题