[hatari-devel] ide.c memory leak and ifdefs

Thomas Huth huth at users.berlios.de
Tue Jan 26 21:41:00 CET 2010


On Tue, 26 Jan 2010 15:10:21 +0200
Eero Tamminen <eerot at users.berlios.de> wrote:

> Hi,
> 
> While checking small memory leak in ide.c, I noticed that it has some
> ifdefs:
> ------
> $ grep 'HAVE.*_M' ide.c
> #if HAVE_MALLOC_H
> #if HAVE_POSIX_MEMALIGN
> #elif HAVE_MEMALIGN
> ------
> 
> If there's no HAVE_POSIX_MEMALIGN defined ide.c uses, instead of
> the (POSIX) standard posix_memalign() call, obsolete memalign() or
> valign() calls.  Unlike memory returned by posix_memalign(), the
> memory returned from these obsolete functions cannot be safely freed
> on all platforms (with Glibc it can).
> 
> Some code in ide.c frees memory returned from the qemu_memalign()
> wrapper, Ide_UnInit didn't, I fixed that.
> 
> The reason why the obsolete functions are used is that we have no
> check for POSIX_MEMALIGN:
> ------
> $ grep 'HAVE.*_M' ../config-default.h
> ------
> 
> Is there any reason to even support these unsafe & obsolete valign()
> & memalign() functions (one can trivially implement aligned malloc
> that works better...)?

IIRC the valloc call was the only function that was available
everywhere. posix_memalign() was not available on MinGW, memalign() was
not available on Mac OS X.

 Thomas



More information about the hatari-devel mailing list