当我想使用 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 打印“未知”?