c语言 - dmalloc 提供返回地址信息显示"未知"?



当我想使用dmalloc-5.5.2检查跨平台上的内存泄漏时。我包含了dmalloc.h,用mips-gcc-4.3编译它,并将它与./libdmalldm.a链接。应用程序工作正常,最后内存耗尽。但显示这样的日志:

1451616386: 4539: not freed: '0x6af408|s1' (560 bytes) from 'data.c:808'    
1451616386: 4539: not freed: '0x6af808|s1' (560 bytes) from 'data.c:808'
1451616386: 4539: not freed: '0x6af408|s1' (560 bytes) from 'data.c:808'
1451616386: 4539: not freed: '0x6af808|s1' (560 bytes) from 'data.c:808'
1451616386: 4539: not freed: '0x6afc08|s1' (560 bytes) from 'data.c:808'
1451616386: 4539: not freed: '0x6b0008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6b1008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6b2008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6b3008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6b4008|s5' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6b5008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6b7008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6b8008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6b9008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6ba008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6bb008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6bc008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6be008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6bf008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6c0008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6c1008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6c2008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6c3008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6c4008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6c5008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6c6008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6c7008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6c8008|s5' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6c9008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6ca008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6cb008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6cc008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6cd008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6ce008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6cf008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6d0008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6d1008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6d2008|s1' (2048 bytes) from 'unknown'
1451616386: 4539: not freed: '0x6d3008|s1' (2048 bytes) from 'unknown'

我认为未知的地方就是内存泄漏的地方。但我不知道为什么dmalloc不能记录内存分配的文件和行。我读了关于dmalloc的文件。我发现:

通常,您可以通过strdup()或其他例程在中分配内存,因此列出strdup例程中内存分配位置的日志文件无助于找到内存泄漏的真正来源-调用strdup的例程。如果没有跟踪调用堆栈的机制,库就无法查看调用方的调用方(可以这么说)是谁。

但在dmalloc.h中,仍然存在:

dmalloc_strndup(__FILE__, __LINE__, (str), -1, 0)

"未知"信息与strdup有关系吗?所以我的问题是,为什么dmalloc打印"未知"?

"未知意味着没有相关文件和行信息的内存。如果您没有在C文件中包含dmalloc.h,或者如果您想跟踪系统功能中可能存在的内存泄漏,这是必要的。">

"无法提供返回地址信息的系统显示为‘未知’。">

http://dmalloc.com/docs/5.3.0/online/dmalloc_17.htmlhttps://stuff.mit.edu/afs/sipb/project/gnucash-test/src/dmalloc-4.8.2/dmalloc.html

如前所述,日志中的未知地址意味着在内存分配过程中没有使用dmalloc实用程序。因此,dmalloc不知道什么是分配器。

库函数是看不到分配器的常见原因之一。由于库函数使用malloc进行分配,因此dmalloc无法捕捉到这一点。

所以,是的。strdup还在方法内部分配内存。这是未知地址的一个例子,因为它在库中进行分配。在这种情况下,您应该使用stackanalysis,例如valgrind。

最新更新