chrisosaurus / dodo

scriptable in place file editor
MIT License
4 stars 1 forks source link

properly clean up allocated instructions #2

Closed chrisosaurus closed 9 years ago

chrisosaurus commented 9 years ago

Currently in the dodo codebase we have instances of i = new_instruction(PRINT); where we then store i in the list of instructions, these are not cleaned up on program exit.

You can see valgrind listing each instance of this by running make test:

chris@Ox1b dodo(master)-> make test
Running test.sh
/usr/bin/valgrind

Writing file

Running dodo
==29503== Memcheck, a memory error detector
==29503== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==29503== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==29503== Command: ./dodo tmp_testing_file
==29503== 
'hello world how are you mutter mutter sl/ash
'
'hello'
==29503== 
==29503== HEAP SUMMARY:
==29503==     in use at exit: 320 bytes in 10 blocks
==29503==   total heap usage: 13 allocs, 3 frees, 2,013 bytes allocated
==29503== 
==29503== 32 bytes in 1 blocks are still reachable in loss record 1 of 5
==29503==    at 0x4C272B8: calloc (vg_replace_malloc.c:566)
==29503==    by 0x400B4D: new_instruction (dodo.c:71)
==29503==    by 0x40135A: parse_quit (dodo.c:426)
==29503==    by 0x40164B: parse (dodo.c:556)
==29503==    by 0x401CE3: main (dodo.c:918)
==29503== 
==29503== 64 bytes in 2 blocks are still reachable in loss record 2 of 5
==29503==    at 0x4C272B8: calloc (vg_replace_malloc.c:566)
==29503==    by 0x400B4D: new_instruction (dodo.c:71)
==29503==    by 0x400F9E: parse_print (dodo.c:291)
==29503==    by 0x4014C5: parse (dodo.c:500)
==29503==    by 0x401CE3: main (dodo.c:918)
==29503== 
==29503== 64 bytes in 2 blocks are still reachable in loss record 3 of 5
==29503==    at 0x4C272B8: calloc (vg_replace_malloc.c:566)
==29503==    by 0x400B4D: new_instruction (dodo.c:71)
==29503==    by 0x40108F: parse_byte (dodo.c:326)
==29503==    by 0x401513: parse (dodo.c:511)
==29503==    by 0x401CE3: main (dodo.c:918)
==29503== 
==29503== 64 bytes in 2 blocks are still reachable in loss record 4 of 5
==29503==    at 0x4C272B8: calloc (vg_replace_malloc.c:566)
==29503==    by 0x400B4D: new_instruction (dodo.c:71)
==29503==    by 0x401241: parse_write (dodo.c:387)
==29503==    by 0x4015FD: parse (dodo.c:544)
==29503==    by 0x401CE3: main (dodo.c:918)
==29503== 
==29503== 96 bytes in 3 blocks are still reachable in loss record 5 of 5
==29503==    at 0x4C272B8: calloc (vg_replace_malloc.c:566)
==29503==    by 0x400B4D: new_instruction (dodo.c:71)
==29503==    by 0x40118D: parse_expect (dodo.c:362)
==29503==    by 0x4015AF: parse (dodo.c:533)
==29503==    by 0x401CE3: main (dodo.c:918)
==29503== 
==29503== LEAK SUMMARY:
==29503==    definitely lost: 0 bytes in 0 blocks
==29503==    indirectly lost: 0 bytes in 0 blocks
==29503==      possibly lost: 0 bytes in 0 blocks
==29503==    still reachable: 320 bytes in 10 blocks
==29503==         suppressed: 0 bytes in 0 blocks
==29503== 
==29503== For counts of detected and suppressed errors, rerun with: -v
==29503== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)

Comparing output

All green

Removing temporary file
chrisosaurus commented 9 years ago

This has been fixed in #3

Thanks @phillid

chrisosaurus commented 9 years ago

A thing of beauty

chris@Ox1b dodo(master)-> make test
CC dodo.c
CC -o dodo
Running test.sh
/usr/bin/valgrind

Writing file

Running dodo
==2237== Memcheck, a memory error detector
==2237== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==2237== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==2237== Command: ./dodo tmp_testing_file
==2237== 
'hello world how are you mutter mutter sl/ash
'
'hello'
==2237== 
==2237== HEAP SUMMARY:
==2237==     in use at exit: 0 bytes in 0 blocks
==2237==   total heap usage: 13 allocs, 13 frees, 2,013 bytes allocated
==2237== 
==2237== All heap blocks were freed -- no leaks are possible
==2237== 
==2237== For counts of detected and suppressed errors, rerun with: -v
==2237== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)

Comparing output

All green

Removing temporary file
phillid commented 9 years ago

That's a good look indeed. Now to figure out how to delete all these ugly dangling commits github seems to be digging up from a bunch of rebasing I did...

chrisosaurus commented 9 years ago

@phillid I don't think you can and it isn't a big deal, from what I can tell github makes a link / counts it when you push the commit, even if you later rebase or possibly even destroy the repo.