Fix malloc() / free() imbalance.

main
theraven 15 years ago
parent 908374672d
commit 6a27408e9e

@ -429,6 +429,7 @@ static id allocate_class(Class cls, size_t extra)
return obj;
}
static void free_object(id obj) {}
id objc_allocate_object(Class cls, int extra)
{
return class_createInstance(cls, extra);
@ -714,6 +715,7 @@ static void debug_free(void *ptr)
PRIVATE struct gc_ops gc_ops_boehm =
{
.allocate_class = allocate_class,
.free_object = free_object,
.malloc = debug_malloc,
.free = debug_free,
};

@ -11,6 +11,11 @@ static id allocate_class(Class cls, size_t extraBytes)
return (id)(addr + 1);
}
static void free_object(id obj)
{
free((void*)(((intptr_t)obj) - 1));
}
static void *alloc(size_t size)
{
return calloc(size, 1);
@ -19,6 +24,7 @@ static void *alloc(size_t size)
PRIVATE struct gc_ops gc_ops_none =
{
.allocate_class = allocate_class,
.free_object = free_object,
.malloc = alloc,
.free = free
};

@ -12,6 +12,10 @@ struct gc_ops
* Allocates enough space for a class, followed by some extra bytes.
*/
id (*allocate_class)(Class, size_t);
/**
* Frees an object.
*/
void (*free_object)(id);
/**
* Allocates some memory that can be used to store pointers. This must be
* used instead of malloc() for internal data structures that will store

@ -358,8 +358,11 @@ id object_copy(id obj, size_t size)
id object_dispose(id obj)
{
call_cxx_destruct(obj);
gc->free(obj);
if (isGCEnabled)
{
call_cxx_destruct(obj);
gc->free_object(obj);
}
return nil;
}

Loading…
Cancel
Save