lewdlime / abcm2ps

abcm2ps is a command line program which converts ABC to music sheet in PostScript or SVG format. It is an extension of abc2ps which may handle many voices per staff. abcm2ps is Copyright © 2014-2016 Jean-Francois Moine.
http://moinejf.free.fr/
GNU General Public License v3.0
82 stars 31 forks source link

Memory leaks #112

Closed hkiel closed 1 year ago

hkiel commented 1 year ago

I instrumented abcm2ps with memory allocation tracking module and found a few 'leaks' when running ./abcm2ps sample.abc

DEBUG 65 remaining items in Memory List.
DEBUG Remaining items in Memory List:
DEBUG 1: 16414 bytes allocated in abcm2ps.c:1113 ("")
DEBUG 2: 16414 bytes allocated in abcm2ps.c:1113 ("")
DEBUG 3: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 4: 16414 bytes allocated in abcm2ps.c:1113 ("(J")
DEBUG 5: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 6: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 7: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 8: 16414 bytes allocated in abcm2ps.c:1113 ("(B")
DEBUG 9: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 10: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 11: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 12: 16414 bytes allocated in abcm2ps.c:1113 ("(:")
DEBUG 13: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 14: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 15: 16414 bytes allocated in abcm2ps.c:1113 ("(|")
DEBUG 16: 16414 bytes allocated in abcm2ps.c:1113 ("(t")
DEBUG 17: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 18: 16414 bytes allocated in abcm2ps.c:1113 ("(2")
DEBUG 19: 16414 bytes allocated in abcm2ps.c:1113 ("(l")
DEBUG 20: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 21: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 22: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 23: 16414 bytes allocated in abcm2ps.c:1113 ("(d")
DEBUG 24: 16414 bytes allocated in abcm2ps.c:1113 ("(*")
DEBUG 25: 16414 bytes allocated in abcm2ps.c:1113 ("("")
DEBUG 26: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 27: 16414 bytes allocated in abcm2ps.c:1113 ("(\")
DEBUG 28: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 29: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 30: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 31: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 32: 16414 bytes allocated in abcm2ps.c:1113 ("(X")
DEBUG 33: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 34: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 35: 16414 bytes allocated in abcm2ps.c:1113 ("(P")
DEBUG 36: 4 bytes allocated in deco.c:927 ("hld")
DEBUG 37: 4 bytes allocated in deco.c:927 ("cpu")
DEBUG 38: 4 bytes allocated in deco.c:927 ("grm")
DEBUG 39: 4 bytes allocated in deco.c:927 ("dnb")
DEBUG 40: 4 bytes allocated in deco.c:927 ("upb")
DEBUG 41: 4 bytes allocated in deco.c:927 ("sld")
DEBUG 42: 4 bytes allocated in deco.c:927 ("emb")
DEBUG 43: 4 bytes allocated in deco.c:927 ("stc")
DEBUG 44: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 45: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 46: 16414 bytes allocated in abcm2ps.c:1113 ("(H")
DEBUG 47: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 48: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 49: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 50: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 51: 9 bytes allocated in glyph.c:255 ("ellipsis")
DEBUG 52: 512 bytes allocated in glyph.c:251 ("")
DEBUG 53: 16414 bytes allocated in abcm2ps.c:1113 ("(@")
DEBUG 54: 16414 bytes allocated in abcm2ps.c:1113 ("(")
DEBUG 55: 8192 bytes allocated in front.c:110 ("w:mem-ber ...")
DEBUG 56: 11 bytes allocated in abcm2ps.c:224 ("sample.abc...")
DEBUG 57: 11 bytes allocated in format.c:205 ("Times-Bold...")
DEBUG 58: 12 bytes allocated in format.c:205 ("Times-Roma...")
DEBUG 59: 13 bytes allocated in format.c:205 ("Times-Ital...")
DEBUG 60: 10 bytes allocated in format.c:205 ("Helvetica")
DEBUG 61: 16 bytes allocated in format.c:417 ("%b %e, %Y ...")
DEBUG 62: 16414 bytes allocated in abcm2ps.c:1071 ("")
DEBUG 63: 16414 bytes allocated in abcm2ps.c:1071 ("(")
DEBUG 64: 16414 bytes allocated in abcm2ps.c:1071 ("(,")
DEBUG 65: 65536 bytes allocated in buffer.c:775 ("0 -22.00 T...")
DEBUG Total number of unfreed items: 65

I guess there should be more places in the code when using other input files and/or parameter flags. This was just to test the infrastructure. I could not find any memory violations yet (allocated memory is 'protected' by a 16 byte wall at both ends, which is checked at free() and end of program)

moinejf commented 1 year ago

abcm2ps is a command line program, not a daemon. It does not need to free the memory it used at exit time.

Yes, it allocates memory in the heap. The allocator (arena) has 3 pools (levels): global, tunes and generation. Memory is allocated as needed, and when either the generation or the tunes (ABC file) are done, the arenas are put in an internal pool of free memory.

Your test generates only one file, then the memory arenas allocated for scanning the tunes are internally freed. But the generation level contains only the memory used by the last generation.

So, every thing is normal.