valgrind在dlopen中报告了内存泄漏?

Ant*_*eru 13 valgrind memory-leaks dlopen

我最近用valgrind调试了一些应用程序,我收到了非常奇怪的报告dlopen.

==1987== 32 bytes in 1 blocks are still reachable in loss record 1 of 2
==1987==    at 0x4C24477: calloc (vg_replace_malloc.c:418)
==1987==    by 0x570F31F: _dlerror_run (dlerror.c:142)
==1987==    by 0x570EEE0: dlopen@@GLIBC_2.2.5 (dlopen.c:88)
        <my call to dlopen>
==1987==
==1987== 264 bytes in 1 blocks are still reachable in loss record 2 of 2
==1987==    at 0x4C25153: malloc (vg_replace_malloc.c:195)
==1987==    by 0x400CD44: _dl_map_object_deps (dl-deps.c:506)
==1987==    by 0x4012DA2: dl_open_worker (dl-open.c:326)
==1987==    by 0x400E385: _dl_catch_error (dl-error.c:178)
==1987==    by 0x40126C6: _dl_open (dl-open.c:615)
==1987==    by 0x570EF65: dlopen_doit (dlopen.c:67)
==1987==    by 0x400E385: _dl_catch_error (dl-error.c:178)
==1987==    by 0x570F2AB: _dlerror_run (dlerror.c:164)
==1987==    by 0x570EEE0: dlopen@@GLIBC_2.2.5 (dlopen.c:88)
        <my call to dlopen>
Run Code Online (Sandbox Code Playgroud)

这看起来像初始化的错误消息dlerror,但查看手册页,它没有说明应如何清除它.知道如何正确摆脱这个吗?

Ara*_*gen 10

能够使用一些"hello world"代码重现此问题,该代码甚至不会调用加载对象中的任何符号. http://pastebin.com/d690bea57

我认为这是libc或valgrind中的一个错误.可在Ubuntu 9.04和Scientific Linux 5.3上重现(分别为20和32字节).

编辑(由Calmarius):

这个简单的代码重现了这个问题:

#include <dlfcn.h>

int main()
{
    void* handle = 0;

    handle = dlopen("libm.so", RTLD_NOW);
    dlclose(handle);    

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

使用此命令编译时:

gcc -Wl,--no-as-needed -g -o stuff  main.c -ldl -lpthread
Run Code Online (Sandbox Code Playgroud)

即使是最新的valgrind 3.11也可以在Ubuntu 14.04上重现这一点

已报告上游错误:https://bugs.kde.org/show_bug.cgi?id = 358980

  • 我发现如果你用pthread_exit(NULL)结束你的代码,valgrind将不报告这个泄漏,即使你根本没有使用pthreads.也许这可以帮助别人.它可能不如编写valgrind抑制文件那么麻烦. (5认同)
  • -1因为粘贴消失了.(否则,我会把它编辑成答案......) (2认同)