Re: [AD] Memory handling problems in 4.3.10

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Memory allocation / leaks should be taken seriuosly... and done correctly.

Having recently implemented my own malloc/free i realize how easy it is to have stray/leaked memory.

I use allegro in 'kiosk' software, that has to run un-attended for weeks, leaks can be eventually fatal. (as memory is exhausted).


aj.



Colin Ward wrote:
Hi all.

I just updated my Amiga port to 4.3.10 and I am having some memory related
problems.

On the Amiga we don't have resource tracking.  This is not normally a
problem but for Allegro games it is, because these games are usually
written on Linux or Windows, where resources are cleaned up automatically
when the game shuts down.  So if you write a replacement malloc/free
implementation that uses _AL_MALLOC and _AL_FREE then at shutdown, you find
that some games are leaking literally megabytes of memory in hundreds of
allocations.

That's ok as my _AL_MALLOC and _AL_FREE implementation can free these.

However, occasionally I have problems because of memory being allocated in a
way that bypasses this mechanism.  A good example is in src/readsmp.c on
line 61, which is:

iter->ext = strdup(aext);
This is a problem because when it is freed on line 126, it is freed with:

_AL_FREE(iter->ext);

So the allocation bypasses _AL_MALLOC so that the allocation is on libc's
list of cells, but it is not on my _AL_MALLOC's list of cells.  So when you
call _AL_FREE, it (_AL_FREE) complains about an invalid block being passed
in.

There are a few of these small problems throughout the code.  Would you be
interested in some patches to fix these?  Until now I have hacked the code
in src but as I am preparing to submit my port to the Allegro svn I need to
fix them properly.  I propose a _AL_STRDUP macro that gets defined along
with _AL_MALLOC and _AL_FREE.  Any comments?






Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/