【问题标题】:Find out memory leaks in a shared library between dlopen and dlclose找出 dlopen 和 dlclose 之间共享库中的内存泄漏
【发布时间】:2018-10-29 09:11:24
【问题描述】:

我们编写了一个共享库(比如 slib.so),它在一个永无止境的可执行文件中被 dlopen'ed、used 和 dlclose'd。 我想在不附加可执行文件的情况下检查库 slib.so 中的内存泄漏。

Linux 中是否有任何工具可以找出共享库中的内存泄漏?所以我需要一个工具来监控 dlopen 和 dlclose 之间的堆,并在 dlclose 之后报告问题。

【问题讨论】:

    标签: memory-leaks shared-libraries memcheck


    【解决方案1】:

    我需要一个工具来监控 dlopen 和 dlclose 之间的堆,并在 dlclose 之后报告问题。

    任何标准泄漏检测工具都可以使用:Valgrind、Leak Sanitizer、TCMalloc heap checker 等。

    您需要做的就是编写一个简单的可执行包装器,例如:

    #include <dlfcn.h>
    
    int main()
    {
      for (int j = 0; j < 10; j++) {
        void *h = dlopen("libslib.so", RTLD_NOW);
        // optionally exercise the library here.
        dlclose(h);
      }
    }
    

    【讨论】:

    • 感谢您的回复!这需要很多时间,因为我们的可执行文件在调用我们的库之前会做很多事情。
    • @Srikanth 这就是为什么你创建一个单独的简单的可执行文件来运行库。
    猜你喜欢
    • 2012-09-19
    • 1970-01-01
    • 2011-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-10
    • 1970-01-01
    相关资源
    最近更新 更多