[kaffe] gc_free vs. KFREE
Marc Kleine-Budde
kleine-budde at gmx.de
Mon Mar 31 09:04:01 PST 2003
On Mon, Mar 31, 2003 at 08:29:43AM -0800, Dalibor Topic wrote:
> Hi Marc,
>
> --- Marc Kleine-Budde <kleine-budde at gmx.de> wrote:
> >
> > My assumption is that KFREE clears the mem at once,
> > and gc_free marks
> > the mem to be freed by the garbage collector? Am I
> > right?
>
> AFAIK, KMALLOC/KFREE should be used for memory that
> does not go through the gc, while gc_malloc/gc_free
> should be used for the rest. Never mix the calls, or
> you'll be in big trouble. KMALLOC/KFREE leave memory
> management to the runtime library, while
> gc_malloc/gc_free do their own memory management.
Okay. Remeber never mix gc_* and K* calls. But if you have a look at the
CVS-sources $KAFFE/libraries/clib/native/ZipFile.c lines 26-36. The mem
for the str is alloced via KMALLOC, but later freed with gc_free. It
this a bug?
struct Hkaffe_util_Ptr*
java_util_zip_ZipFile_openZipFile0(Hjava_lang_String* fname)
{
jarFile* zip;
char* str;
str = checkPtr(stringJava2C(fname));
zip = openJarFile(str);
gc_free(str);
return ((struct Hkaffe_util_Ptr*)zip);
}
$KAFFE/kaffe/kaffevm/string.c 36-46
/*
* Convert a Java string into a KMALLOC()'d C string buffer.
*/
char*
stringJava2C(const Hjava_lang_String* js)
{
char* str;
str = KMALLOC(STRING_SIZE(js) + 1);
if (str != 0) {
stringJava2CBuf(js, str, STRING_SIZE(js) + 1);
}
return(str);
}
regards - Marc
More information about the kaffe
mailing list