[dmd-internals] DMD internal memory management issue

Denis 2korden at gmail.com
Wed Dec 9 00:53:08 PST 2009


On Tue, Dec 8, 2009 at 10:49 PM, Walter Bright <walter at digitalmars.com> wrote:
> Good catch, fixed with changeset 288.
>
> Denis wrote:
>>
>> I came across one memory allocation related problem in DMD and decided
>> to make a post about it in this list.
>>
>>
>
> _______________________________________________
> dmd-internals mailing list
> dmd-internals at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-internals
>

That's the most obvious case. Unfortunately, there are cases that are
harder to track and fix.
For example, OutBuffer uses mem.malloc/mem.realloc and result is
sometimes assigned to elem*, Symbol* and block* variables (and freed
by backend).
A string, created in FileName::forceExt (it evaluates return new
FileName(s, 0); which does mem.strdup in String ctor) is also
deallocated in backend.
el_setLoc does raw pointer assignment. Who knows how original string
was allocated? Deallocated in backend.

You could probably catch all the occurrences saving all the allocated
pinters in a map and checking that the pointer to deallocate is indeed
present in that map. MEM_DEBUG already half of the needed
functionality. Fortunately, all the backend allocations/deallocation
are forwarded to tk/mem.c (at least the problematic ones).


More information about the dmd-internals mailing list