我的程序中有轻微的内存泄漏,我不确定它是在我的allocs还是在内部c结构中。我正在使用的唯一的mallocs是:
results = (int*) malloc (instance_n * sizeof (int) );
instances = (char**) malloc (instance_n * sizeof (char*) );
for (i = 0; i < instance_n; i++) {
instances[i] = (char*) malloc (1001 * sizeof (char) );
}
List_add (); (standard doubly linked list. Never gave me a problem)
我在同一个地方释放所有东西:
free (results);
List_clear (&dynamic);
for (i = 0; i < instance_n; i++) {
free (instances[i]);
}
free (instances);
BTW:List_clear =
Node* node = list->last;
if (node == NULL) return;
while (node->previous != NULL)
{
node = node->previous;
free (node->next);
}
free (list->first);
此外,我正在使用timeval和FILE结构(文件在方法结束时被删除)
我错过了什么吗?对我来说,我肯定看起来像是在释放一切。我从来没有遇到过内存泄漏问题所以我调试它很糟糕,但Valgrind一直指出这个内存泄漏:
==3180== HEAP SUMMARY:
==3180== in use at exit: 62,951 bytes in 361 blocks
==3180== total heap usage: 556 allocs, 195 frees, 115,749 bytes allocated
==3180==
==3180== LEAK SUMMARY:
==3180== definitely lost: 8,624 bytes in 14 blocks
==3180== indirectly lost: 1,168 bytes in 5 blocks
==3180== possibly lost: 4,925 bytes in 68 blocks
==3180== still reachable: 48,234 bytes in 274 blocks
==3180== suppressed: 0 bytes in 0 blocks
==3180== Rerun with --leak-check=full to see details of leaked memory
==3180==
我不禁注意到“14块”部分,但我的代码中没有一部分分配少于20个部分,而8624字节是4字节的倍数,所以它很可能是整数泄漏。
提前致谢
答案 0 :(得分:0)
我刚刚在valgrind上找到了这个条款:
==3821== WARNING: Support on MacOS 10.8 is experimental and mostly broken.
==3821== WARNING: Expect incorrect results, assertions and crashes.
==3821== WARNING: In particular, Memcheck on 32-bit programs will fail to
==3821== WARNING: detect any errors associated with heap-allocated data.
其他一些人在MacOSX 10.8上得到了相同的8624字节泄漏,所以我猜这是误报。