IMCC has a fair few memory leaks, and most of them come (eventually) from 
calls to str_dup().

Why are there so many calls to str_dup()?  Look in compilers/imcc/symreg.c at 
_mk_symreg().  This function takes a parameter, char *name.  Here's the funny 
part:

        SymReg * r = _get_sym_typed(hsh, name, t);

        if (r) {
                free(name);
                return r;
        }

If you're asking yourself "Self, why would a function called _mk_symreg() that 
takes a char * ever need to free that pointer?", then you get a cookie.

Plenty of other functions in IMCC mysteriously free passed-in pointers, which 
is probably why there are so many defensive str_dup() calls splattered all 
over the place.  Moving memory management back where it belongs (that is, 
when you're done with the pointer) ought to make it easier to plug these 
leaks.

Patches more than welcome -- I've found that removing a random str_dup() then 
running 'make' often makes a nice segfault that GDB is more than happy to 
help you resolve.

-- c

Reply via email to