gcc 4.5.1 c89ストールアップ後にメモリを解放できません
メモリを解放しようとしています。しかし、私がvalgrindでチェックすると、メモリは解放されていません。私は何が間違っているのだろうと思っています。
typedef struct tag_cand_results {
char *candidate_winners[NUMBER_OF_CANDIDATES];
} cand_results;
が、私はこのような構造のオブジェクトを作成します:
cand_results *results = NULL;
私は構造のためのいくつかのメモリを割り当てる
は、私は次のような構造を持っています。
results = calloc(1, sizeof *results);
それ
results->candidate_winners[0] = strdup("Steve Martin");
results->candidate_winners[1] = strdup("Jack Jones");
にいくつかのデータを割り当てそれから私は、割り当てられたすべてのメモリを解放しよう:
free(results->candidate_winners[0]);
free(results->candidate_winners[1]);
free(results);
Just to be safe assign to NULL
results = NULL;
私はvalgrindのからの次の出力を取得します。
==8119== 72 bytes in 6 blocks are definitely lost in loss record 1 of 2
==8119== at 0x4A05E46: malloc (vg_replace_malloc.c:195)
==8119== by 0x3FE2E82A91: strdup (strdup.c:43)
==8119== by 0x400E5A: main (driver.c:116)
==8119==
==8119== 72 bytes in 6 blocks are definitely lost in loss record 2 of 2
==8119== at 0x4A05E46: malloc (vg_replace_malloc.c:195)
==8119== by 0x3FE2E82A91: strdup (strdup.c:43)
==8119== by 0x400E72: main (driver.c:117)
なぜメモリが解放されていないのですか?
任意の提案のための多くのおかげで、
あなたはValgrindのは、まだこのように文句どの最小*完全*プログラムを投稿することができます。 – NPE
私のソースコードのどこかで何かが起こっています。下記のPaxにコメントを投稿しました。 – ant2009