memory-leaks - dlopen 中 valgrind 报告的内存泄漏?

标签 memory-leaks valgrind 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>

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

最佳答案

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

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

编辑(由卡尔马留斯):

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

#include <dlfcn.h>

int main()
{
    void* handle = 0;

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

    return 0;
}

使用此命令编译时:
gcc -Wl,--no-as-needed -g -o stuff  main.c -ldl -lpthread

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

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

关于memory-leaks - dlopen 中 valgrind 报告的内存泄漏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1542457/

相关文章:

c++ - 为什么这个动态库加载代码用gcc可以用?

Azure 服务在几天后终止

c++ - 运行时错误 : Access violation writing loacation while deleting a pointer in dynamic memory allocation

java - 使用 Java 中的 GroovyClassLoader - 未 GC 的类

c++ - Valgrind 错误 : Syscall param epoll_pwait(sigmask) points to unaddressable byte(s)

C++:使用 dlopen() 加载共享库时 undefined symbol

java - SocksSocketImpl finalize 方法的内存泄漏

debugging - 使valgrind在第一个错误后立即停止

c - Helgrind 报告单线程上的数据争用

c - valgrind 给出错误但无法找到位置