gcc 4.5.1 c89
I'm trying to free my memory. However, when I check valgrind, the memory was not freed. I am wondering what I am doing wrong.
I have the following structure:
typedef struct tag_cand_results {
char *candidate_winners[NUMBER_OF_CANDIDATES];
} cand_results;
I create an object of this structure:
cand_results *results = NULL;
I allocate some memory for the structure.
results = calloc(1, sizeof *results);
Assign him some data
results->candidate_winners[0] = strdup("Steve Martin");
results->candidate_winners[1] = strdup("Jack Jones");
Then I try to free all the allocated memory:
free(results->candidate_winners[0]);
free(results->candidate_winners[1]);
free(results);
Just to be safe assign to NULL
results = NULL;
I get the following result from 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)
I do not know why the memory was not freed?
Thanks so much for any suggestions,
source
share