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

Eero Tamminen eerot at users.berlios.de
Tue Jan 26 14:10:21 CET 2010


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...)?



	- Eero



More information about the hatari-devel mailing list