C复杂内存泄漏



我的程序中有一个轻微的内存泄漏,我不确定它是在我的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字节的倍数,所以很可能是整数泄漏。

提前感谢

我刚刚在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字节泄漏,所以我想这是一个假阳性。

相关内容

  • 没有找到相关文章