プログラムでわずかなメモリ リークが発生していますが、それが allocs にあるのか、内部の c 構造体にあるのかわかりません。私が使用しているmallocは次のとおりです。
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);
ところで: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 バイトの倍数であるため、整数リークである可能性が最も高いです。
前もって感謝します