diff --git a/ChangeLog b/ChangeLog index 1cb748fa8..5caef53ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2009-08-10 Richard Frith-Macdonald + + * Source/NSData.m: Fix memory leak introduced with GC changes. + 2009-08-05 Richard Frith-Macdonald * Source/NSFileManager.m: diff --git a/Source/NSData.m b/Source/NSData.m index f635043b5..00a5e2bfb 100644 --- a/Source/NSData.m +++ b/Source/NSData.m @@ -3699,25 +3699,30 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos) #if GS_WITH_GC tmp = NSAllocateCollectable(size, 0); -#else - tmp = NSZoneMalloc(zone, size); -#endif if (tmp == 0) { [NSException raise: NSMallocException format: @"Unable to set data capacity to '%d'", size]; } - if (bytes) { memcpy(tmp, bytes, capacity < size ? capacity : size); -#if GS_WITH_GC if (owned == YES) { NSZoneFree(NSDefaultMallocZone(), bytes); owned = NO; } + } #else + tmp = NSZoneMalloc(zone, size); + if (tmp == 0) + { + [NSException raise: NSMallocException + format: @"Unable to set data capacity to '%d'", size]; + } + if (bytes) + { + memcpy(tmp, bytes, capacity < size ? capacity : size); if (zone == 0) { zone = NSDefaultMallocZone(); @@ -3726,8 +3731,12 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos) { NSZoneFree(zone, bytes); } -#endif } + else if (zone == 0) + { + zone = NSDefaultMallocZone(); + } +#endif bytes = tmp; capacity = size; growth = capacity/2;