malloc question

e. lambrecht eml@enws786.eas.asu.edu
Thu, 26 Feb 1998 09:48:40 -0700


Hey everybody,
 I'm trying to integrate some C code (specifically, the ImageMagick
library) with my Java code that runs under kaffe, but I'm having some
problems.

I think it all boils down to dealing with memory allocation. In my
magickimage.c file that implements the interface to kaffe, the first
thing I need to do is allocate space for an ImageInfo structure:

  image_info = malloc(sizeof(image_info));

now I see that the native.h header file redefines malloc to be
gc_malloc. This seems ok at first, but later in the code I ask the
ImageMagick library to free up the memory used by the image_info
structure:

  DestroyImageInfo(image_info);

unfortunately, the whole thing conks out after this. Would this be
because the DestroyImageInfo function is using the normal free()
rather than kaffe's gc_free?

I tried skipping the '#define malloc(A) gc_malloc(A)' so that my code
would use the normal malloc, and the ImageMagick 'free' call would
work. My malloc above works fine, but then my code dies a few lines
later when the ImageMagick library indirectly makes a call to malloc()
via the fopen() call. According to gdb, the code is dieing at
chunk_free() in malloc.c:2824.

I know I haven't given any really good details here - so I guess what
I'm asking is: what memory allocation considerations do I have to make
for my .c code to work with kaffe?

Eric...  
(p.s. - good work on the compiler. My pure java code works wonderfully
in it)