fix memory leak

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28448 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2009-08-10 14:13:09 +00:00
parent fbb35d1684
commit 10d2d0016c
2 changed files with 19 additions and 6 deletions

View file

@ -1,3 +1,7 @@
2009-08-10 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSData.m: Fix memory leak introduced with GC changes.
2009-08-05 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSFileManager.m:

View file

@ -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;