Fixed memory leak

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3522 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1999-01-05 10:45:32 +00:00
parent 4a13ae7fc2
commit 64135f2cdd
2 changed files with 13 additions and 7 deletions

View file

@ -2,6 +2,7 @@ Tue Jan 5 9:45:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* src/NSTask.m: Workaround for bug in linux waitpid(), general
tidying, clean up descriptors in child process.
* src/NSString.m: ([-dataUsingEncoding:]) fixed memory leak.
Mon Jan 4 15:35:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>

View file

@ -2100,15 +2100,19 @@ else
|| (encoding==NSSymbolStringEncoding)
|| (encoding==NSCyrillicStringEncoding))
{
unsigned char *buff;
char t;
OBJC_MALLOC(buff, char, len+1);
unsigned char *buff;
buff = (unsigned char*)NSZoneMalloc(NSDefaultMallocZone(), len+1);
if(!flag)
for(count=0; count<len; count++)
if((t = encode_unitochar([self characterAtIndex: count], encoding)))
buff[count] = t;
else
return nil;
{
NSZoneFree(NSDefaultMallocZone(), buff);
return nil;
}
else /* lossy */
for(count=0; count<len; count++)
if((t = encode_unitochar([self characterAtIndex: count], encoding)))
@ -2127,19 +2131,20 @@ else
simple replacement for character */
buff[count] = '*';
};
buff[count]=0;
return [NSData dataWithBytes: (char *)buff length: count];
buff[count]=0;
return [NSData dataWithBytesNoCopy: buff length: count+1];
}
else
if(encoding==NSUnicodeStringEncoding)
{
unichar *buff;
OBJC_MALLOC(buff, unichar, len+2);
buff = (unichar*)NSZoneMalloc(NSDefaultMallocZone(), 2*(len+2));
buff[0]=0xFEFF;
for(count=0; count<len; count++)
buff[count+1]=[self characterAtIndex: count];
buff[count+1]= (unichar)0;
return [NSData dataWithBytes: (char *)buff length: 2*(count+1)];
return [NSData dataWithBytesNoCopy: buff length: 2*(len+2)];
}
else /* UTF8 or EUC */
[self notImplemented:_cmd];