mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
Fix memory leak
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@23068 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d083a39605
commit
61e201d3fe
2 changed files with 24 additions and 9 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
2006-06-17 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/GSString.m: Fix memory leak.
|
||||||
|
|
||||||
2006-06-16 Richard Frith-Macdonald <rfm@gnu.org>
|
2006-06-16 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Headers/Foundation/NSURLCredential.h:
|
* Headers/Foundation/NSURLCredential.h:
|
||||||
|
|
|
@ -3482,7 +3482,8 @@ agree, create a new GSUnicodeInlineString otherwise.
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
if (_flags.free == 1 && _zone != 0 && _contents.c != 0)
|
NSAssert(_flags.free == 1 && _zone != 0, NSInternalInconsistencyException);
|
||||||
|
if (_contents.c != 0)
|
||||||
{
|
{
|
||||||
NSZoneFree(self->_zone, self->_contents.c);
|
NSZoneFree(self->_zone, self->_contents.c);
|
||||||
self->_contents.c = 0;
|
self->_contents.c = 0;
|
||||||
|
@ -3639,6 +3640,13 @@ agree, create a new GSUnicodeInlineString otherwise.
|
||||||
BOOL isLatin1 = NO;
|
BOOL isLatin1 = NO;
|
||||||
BOOL shouldFree = NO;
|
BOOL shouldFree = NO;
|
||||||
|
|
||||||
|
_flags.free = YES;
|
||||||
|
#if GS_WITH_GC
|
||||||
|
_zone = GSAtomicMallocZone();
|
||||||
|
#else
|
||||||
|
_zone = GSObjCZone(self);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (length > 0)
|
if (length > 0)
|
||||||
{
|
{
|
||||||
fixBOM((unsigned char**)&bytes, &length, &shouldFree, encoding);
|
fixBOM((unsigned char**)&bytes, &length, &shouldFree, encoding);
|
||||||
|
@ -3656,6 +3664,10 @@ agree, create a new GSUnicodeInlineString otherwise.
|
||||||
if (encoding == NSASCIIStringEncoding)
|
if (encoding == NSASCIIStringEncoding)
|
||||||
{
|
{
|
||||||
RELEASE(self);
|
RELEASE(self);
|
||||||
|
if (shouldFree == YES)
|
||||||
|
{
|
||||||
|
NSZoneFree(NSZoneFromPointer(chars), chars);
|
||||||
|
}
|
||||||
return nil; // Invalid data
|
return nil; // Invalid data
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -3675,16 +3687,16 @@ agree, create a new GSUnicodeInlineString otherwise.
|
||||||
{
|
{
|
||||||
if (shouldFree == YES)
|
if (shouldFree == YES)
|
||||||
{
|
{
|
||||||
|
_zone = NSZoneFromPointer(chars);
|
||||||
_contents.c = chars;
|
_contents.c = chars;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_contents.c = NSZoneMalloc(GSObjCZone(self), length);
|
_contents.c = NSZoneMalloc(_zone, length);
|
||||||
memcpy(_contents.c, chars, length);
|
memcpy(_contents.c, chars, length);
|
||||||
}
|
}
|
||||||
_count = length;
|
_count = length;
|
||||||
_flags.wide = 0;
|
_flags.wide = 0;
|
||||||
_flags.free = YES;
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3697,7 +3709,7 @@ agree, create a new GSUnicodeInlineString otherwise.
|
||||||
unsigned l = 0;
|
unsigned l = 0;
|
||||||
|
|
||||||
if (GSToUnicode(&u, &l, (unsigned char*)chars, length, encoding,
|
if (GSToUnicode(&u, &l, (unsigned char*)chars, length, encoding,
|
||||||
GSObjCZone(self), 0) == NO)
|
_zone, 0) == NO)
|
||||||
{
|
{
|
||||||
RELEASE(self);
|
RELEASE(self);
|
||||||
if (shouldFree == YES)
|
if (shouldFree == YES)
|
||||||
|
@ -3724,10 +3736,9 @@ agree, create a new GSUnicodeInlineString otherwise.
|
||||||
if (isASCII == YES
|
if (isASCII == YES
|
||||||
|| (internalEncoding == NSISOLatin1StringEncoding && isLatin1 == YES))
|
|| (internalEncoding == NSISOLatin1StringEncoding && isLatin1 == YES))
|
||||||
{
|
{
|
||||||
_contents.c = NSZoneMalloc(GSObjCZone(self), length);
|
_contents.c = NSZoneMalloc(_zone, length);
|
||||||
_count = length;
|
_count = length;
|
||||||
_flags.wide = 0;
|
_flags.wide = 0;
|
||||||
_flags.free = 1;
|
|
||||||
while (length-- > 0)
|
while (length-- > 0)
|
||||||
{
|
{
|
||||||
_contents.c[length] = ((unichar*)chars)[length];
|
_contents.c[length] = ((unichar*)chars)[length];
|
||||||
|
@ -3742,17 +3753,16 @@ agree, create a new GSUnicodeInlineString otherwise.
|
||||||
{
|
{
|
||||||
if (shouldFree == YES)
|
if (shouldFree == YES)
|
||||||
{
|
{
|
||||||
|
_zone = NSZoneFromPointer(chars);
|
||||||
_contents.u = (unichar*)chars;
|
_contents.u = (unichar*)chars;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_contents.u = NSZoneMalloc(GSObjCZone(self),
|
_contents.u = NSZoneMalloc(_zone, length * sizeof(unichar));
|
||||||
length * sizeof(unichar));
|
|
||||||
memcpy(_contents.u, chars, length * sizeof(unichar));
|
memcpy(_contents.u, chars, length * sizeof(unichar));
|
||||||
}
|
}
|
||||||
_count = length;
|
_count = length;
|
||||||
_flags.wide = 1;
|
_flags.wide = 1;
|
||||||
_flags.free = YES;
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3888,6 +3898,7 @@ agree, create a new GSUnicodeInlineString otherwise.
|
||||||
|
|
||||||
- (id) makeImmutableCopyOnFail: (BOOL)force
|
- (id) makeImmutableCopyOnFail: (BOOL)force
|
||||||
{
|
{
|
||||||
|
NSAssert(_flags.free == 1 && _zone != 0, NSInternalInconsistencyException);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
GSDebugAllocationRemove(isa, self);
|
GSDebugAllocationRemove(isa, self);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue