Fix leaks

This commit is contained in:
rfm 2024-11-15 21:21:41 +00:00
parent 77c66e3d95
commit 088b76bed1
10 changed files with 71 additions and 65 deletions

View file

@ -6592,6 +6592,7 @@ static NSFileManager *fm = nil;
&stop);
}
}
ubrk_close(breakIterator);
#else
NSWarnLog(@"NSStringEnumerationByWords and NSStringEnumerationBySentences"
@" are not supported when GNUstep-base is compiled without ICU.");

View file

@ -23,6 +23,8 @@ implementations of the NSString methods in NSString itself.
length: (NSUInteger)l
encoding: (NSStringEncoding)encoding
{
if (characters) free(characters);
characters = NULL;
if (l > 0)
{
if (encoding == NSUnicodeStringEncoding)
@ -37,7 +39,7 @@ implementations of the NSString methods in NSString itself.
s = [[NSString alloc] initWithBytes: c
length: l
encoding: encoding];
if (s == nil) return nil;
if (s == nil) {RELEASE(self); return nil;}
l = [s length] * sizeof(unichar);
characters = malloc(l);
[s getCharacters: characters];
@ -53,6 +55,8 @@ implementations of the NSString methods in NSString itself.
encoding: (NSStringEncoding)encoding
freeWhenDone: (BOOL)freeWhenDone
{
if (characters) free(characters);
characters = NULL;
if (l > 0)
{
if (encoding == NSUnicodeStringEncoding)
@ -68,7 +72,7 @@ implementations of the NSString methods in NSString itself.
length: l
encoding: encoding
freeWhenDone: freeWhenDone];
if (s == nil) return nil;
if (s == nil) {RELEASE(self); return nil;}
l = [s length] * sizeof(unichar);
characters = malloc(l);
[s getCharacters: characters];

View file

@ -39,7 +39,7 @@ Basic sanity test.
*/
BOOL test_initWithCString(void)
{
NSString *test1 = [[stringClass alloc] initWithCString: "ascii"];
NSString *test1 = AUTORELEASE([[stringClass alloc] initWithCString: "ascii"]);
NSString *sanity = @"ascii";
if (!test1)
@ -117,9 +117,9 @@ test_encoding(void)
NSData *d = [[NSData alloc] initWithBytes: "foo" length: 3];
NSString *s = [[stringClass alloc] initWithData: d encoding: 0];
PASS(s == nil, "-initWithData:encoding: gives nil for invalid encodings")
DESTROY(d);
PASS(s == nil, "-initWithData:encoding: gives nil for invalid encodings")
DESTROY(s);
}
test_encodings_helper(NSASCIIStringEncoding,

View file

@ -31,7 +31,7 @@ int main(int argc, char **argv)
h = [s hash];
PASS(h != 0, "[NSConstantString hash] does not return 0");
s = [[NSString alloc] initWithString: s];
s = [NSString stringWithString: s];
h = [s hash];
PASS(h != 0, "[NSString hash] does not return 0");

View file

@ -16,7 +16,7 @@ int main(int argc, char **argv)
unichar characters[3]={'a',0,'b'};
NSRange r;
normalString = [[NSString alloc] initWithCharacters: characters length: 3];
normalString = AUTORELEASE([[NSString alloc] initWithCharacters: characters length: 3]);
PASS([constantString length] == 3, "nuls in constant strings");
PASS([normalString length] == 3, "nuls in non-constant strings");

View file

@ -9,16 +9,16 @@ int main()
unichar theUniChar[1] = {0xe5};
theString = [NSString stringWithCharacters:theUniChar length:1];
PASS([theString isEqual:[[NSString alloc] initWithCString: [theString cStringUsingEncoding: NSISOLatin1StringEncoding] encoding: NSISOLatin1StringEncoding]],"foo");
PASS([theString isEqual: AUTORELEASE([[NSString alloc] initWithCString: [theString cStringUsingEncoding: NSISOLatin1StringEncoding] encoding: NSISOLatin1StringEncoding])],"foo");
NS_DURING
PASS([theString isEqual:[[NSString alloc] initWithCString: [theString cString]]],"foo");
PASS([theString isEqual: AUTORELEASE([[NSString alloc] initWithCString: [theString cString]])],"foo");
NS_HANDLER
PASS(1,"bar");
NS_ENDHANDLER
NS_DURING
PASS([theString isEqual:[[NSMutableString alloc] initWithCString: [theString cString]]],"foo2");
PASS([theString isEqual: AUTORELEASE([[NSMutableString alloc] initWithCString: [theString cString]])],"foo2");
NS_HANDLER
PASS(1,"bar2");
NS_ENDHANDLER

View file

@ -47,15 +47,15 @@ int main (int argc, const char * argv[])
PASS([s1 compare: s2 options: NSNumericSearch] == NSOrderedDescending,
"11 is greater than 2");
a1 = [[NSArray alloc] initWithObjects:
a1 = [NSArray arrayWithObjects:
@"2", @"1", @"10", @"11", @"20", @"3", nil];
a = [[NSArray alloc] initWithObjects:
a = [NSArray arrayWithObjects:
@"1", @"10", @"11", @"2", @"20", @"3", nil];
a2 = [a1 sortedArrayUsingSelector: @selector(compare:)];
PASS_EQUAL(a2, a, "text sort");
a = [[NSArray alloc] initWithObjects:
a = [NSArray arrayWithObjects:
@"1", @"2", @"3", @"10", @"11", @"20", nil];
a2 = [a1 sortedArrayUsingSelector: @selector(numericCompare:)];
PASS_EQUAL(a2, a, "numeric sort");

View file

@ -45,7 +45,7 @@ int main(void)
uni[0] = 0xdbff;
uni[1] = 0xdfff;
exp = [[NSString alloc] initWithCharacters: uni length: 2];
exp = AUTORELEASE([[NSString alloc] initWithCharacters: uni length: 2]);
buf[0] = 0xf4;
buf[1] = 0x8f;
buf[2] = 0xbf;

View file

@ -21,6 +21,7 @@ int main()
cstr = [[NSString alloc] initWithData: adat encoding: NSUTF8StringEncoding];
PASS((cstr != nil && [cstr isKindOfClass: [NSString class]]),
"We can convert to UTF8 Encoding");
RELEASE(cstr);
[arp release]; arp = nil;
return 0;