[AD] Memory handling problems in 4.3.10

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


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?

-- 
/-------------------------------------------------------------------\
[Hitman/Code HQ - 6502/z80/68000/604e/80x86/ARM coder - Amiga rulez!]
[VZ-200/VIC-20/MZ-700/c16/c64*10/c128*8/Plus-4/CPC464/CD32/500*2    ]
[600/1000/1200*2/A4000/SNES/N64/Dreamcast/Athlon 1100/AmigaOne      ]
[Assembly Language: The most fun you can have with your clothes on! ]
\-------------------------------------------------------------------/





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