Memory Leak in C free() -


i'm running valgrind , it's telling me need free , i'm not sure that. points line "toinsert->value = linkedlist->copy(element);

where run free , on data?

"

void linkedlist_append(linkedlist *linkedlist, void *element) {  listnode *toinsert = (listnode*)malloc(sizeof(listnode)); toinsert->value = linkedlist->copy(element); toinsert->next = null; listnode *last = linkedlist->head;  if (last==null)     linkedlist->head  = toinsert;  else{     while(last-> next !=null){         last = last->next;      }     last->next = toinsert;  } linkedlist->size++;  } 

output valgrind:

> ^c==30515==  ==30515== heap summary: ==30515==     in use @ exit: 287 bytes in 47 blocks ==30515==   total heap usage: 95 allocs, 1,038 frees, 2,159 bytes allocated ==30515==  ==30515== 247 bytes in 46 blocks lost in loss record 2 of 2 ==30515==    @ 0x4c28c20: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==30515==    0x4011ac: string_copy (string_fns.c:27) ==30515==    0x4012ce: linkedlist_append (linkedlist.c:87) ==30515==    0x4017bd: add_file (tester.c:194) ==30515==    0x400fe1: main (tester.c:136) ==30515==  ==30515== leak summary: ==30515==    lost: 247 bytes in 46 blocks ==30515==    indirectly lost: 0 bytes in 0 blocks ==30515==      possibly lost: 0 bytes in 0 blocks ==30515==    still reachable: 40 bytes in 1 blocks ==30515==         suppressed: 0 bytes in 0 blocks ==30515== reachable blocks (those pointer found) not shown. ==30515== see them, rerun with: --leak-check=full --show-leak-kinds=all ==30515==  ==30515== counts of detected , suppressed errors, rerun with: -v ==30515== error summary: 2200 errors 10 contexts (suppressed: 0 0) 

valgrind pointing location of malloc never freed. before terminate program, need iterate through list free elements.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -