Skip to content

Commit

Permalink
More leaks fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Nov 16, 2024
1 parent aedd13d commit c7f0c27
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 40 deletions.
6 changes: 3 additions & 3 deletions Tests/base/NSNumber/test00.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ int main()
PASS(200 == [val1 unsignedShortValue],
"NSDecimalNumber unsignedShortValue works")

val1 = [[NSNumber alloc] initWithLongLong: LLONG_MIN];
val2 = [[NSNumber alloc] initWithUnsignedLongLong:
(unsigned long long)LLONG_MAX + 1];
val1 = AUTORELEASE([[NSNumber alloc] initWithLongLong: LLONG_MIN]);
val2 = AUTORELEASE([[NSNumber alloc] initWithUnsignedLongLong:
(unsigned long long)LLONG_MAX + 1]);
PASS([val1 compare: val2] == NSOrderedAscending,
"comparison of min signed with max unsigned works")

Expand Down
2 changes: 1 addition & 1 deletion Tests/base/NSNumberFormatter/basic.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int main()
[NSNumberFormatter
setDefaultFormatterBehavior: NSNumberFormatterBehavior10_0];

TEST_FOR_CLASS(@"NSNumberFormatter",[NSNumberFormatter alloc],
TEST_FOR_CLASS(@"NSNumberFormatter", AUTORELEASE([NSNumberFormatter alloc]),
"+[NSNumberFormatter alloc] returns a NSNumberFormatter");

fmt = [[[NSNumberFormatter alloc] init] autorelease];
Expand Down
2 changes: 1 addition & 1 deletion Tests/base/NSObject/test01.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int main()
![[[NSArray new] autorelease] isClass]),
"-isClass returns NO on an instance");

evilObject = [MyEvilClass new];
evilObject = AUTORELEASE([MyEvilClass new]);
[evilObject setInfo:1];
PASS(![evilObject isClass],
"-isClass returns NO on an instance (special test for broken libobjc)");
Expand Down
12 changes: 7 additions & 5 deletions Tests/base/NSObject/test02.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,22 @@ - (void) doNothingCategory

int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
ENTER_POOL
id instance = AUTORELEASE([NicolaTest new]);

PASS([NicolaTest conformsToProtocol:@protocol(DoingNothing)],
"+conformsToProtocol returns YES on an implemented protocol");
PASS([NicolaTest conformsToProtocol:@protocol(DoingNothingCategory)],
"+conformsToProtocol returns YES on a protocol implemented in a category");
PASS(![NicolaTest conformsToProtocol:@protocol(NSCoding)],
"+conformsToProtocol returns NO on an unimplemented protocol");
PASS([[NicolaTest new] conformsToProtocol:@protocol(DoingNothing)],
PASS([instance conformsToProtocol:@protocol(DoingNothing)],
"-conformsToProtocol returns YES on an implemented protocol");
PASS([[NicolaTest new] conformsToProtocol:@protocol(DoingNothingCategory)],
PASS([instance conformsToProtocol:@protocol(DoingNothingCategory)],
"-conformsToProtocol returns YES on a protocol implemented in a category");
PASS(![[NicolaTest new] conformsToProtocol:@protocol(NSCoding)],
PASS(![instance conformsToProtocol:@protocol(NSCoding)],
"-conformsToProtocol returns NO on an unimplemented protocol");

[arp release]; arp = nil;
LEAVE_POOL
return 0;
}
20 changes: 9 additions & 11 deletions Tests/base/NSOperation/basic.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

int main()
{
ENTER_POOL
id obj1;
id obj2;
NSMutableArray *testObjs = [[NSMutableArray alloc] init];
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSMutableArray *testObjs = [NSMutableArray array];

test_alloc(@"NSOperation");
obj1 = [NSOperation new];
obj1 = AUTORELEASE([NSOperation new]);
PASS((obj1 != nil), "can create an operation");
[testObjs addObject: obj1];
test_NSObject(@"NSOperation", testObjs);
Expand All @@ -36,7 +36,7 @@ int main()
PASS(([obj1 queuePriority] == NSOperationQueuePriorityVeryHigh),
"operation has very high priority");

obj2 = [NSOperation new];
obj2 = AUTORELEASE([NSOperation new]);
[obj2 addDependency: obj1];
PASS(([[obj2 dependencies] isEqual: testObjs]),
"operation has added dependency");
Expand All @@ -53,8 +53,7 @@ int main()
"dependency removal works");
PASS(([obj2 isReady] == YES), "operation without dependency is ready");

[obj1 release];
obj1 = [NSOperation new];
obj1 = AUTORELEASE([NSOperation new]);
[testObjs replaceObjectAtIndex: 0 withObject: obj1];
[obj2 addDependency: obj1];
# if __has_feature(blocks)
Expand All @@ -72,8 +71,7 @@ int main()
PASS(([obj2 isReady] == YES), "operation with finished dependency is ready");

[obj2 removeDependency: obj1];
[obj1 release];
obj1 = [NSOperation new];
obj1 = AUTORELEASE([NSOperation new]);
[testObjs replaceObjectAtIndex: 0 withObject: obj1];
[obj2 addDependency: obj1];
[obj2 cancel];
Expand All @@ -92,7 +90,7 @@ int main()


test_alloc(@"NSOperationQueue");
obj1 = [NSOperationQueue new];
obj1 = AUTORELEASE([NSOperationQueue new]);
PASS((obj1 != nil), "can create an operation queue");
[testObjs removeAllObjects];
[testObjs addObject: obj1];
Expand Down Expand Up @@ -121,11 +119,11 @@ int main()
NSInvalidArgumentException,
"NSOperationQueue cannot be given negative count");

obj2 = [NSOperation new];
obj2 = AUTORELEASE([NSOperation new]);
[obj1 addOperation: obj2];
[NSThread sleepForTimeInterval: 1.0];
PASS(([obj2 isFinished] == YES), "queue ran operation");

[arp release]; arp = nil;
LEAVE_POOL
return 0;
}
2 changes: 1 addition & 1 deletion Tests/base/NSOrderedSet/basic.m
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ int main()

NSOrderedSet *testObj, *testObj2;
NSMutableOrderedSet *mutableTest1, *mutableTest2;
NSMutableArray *testObjs = [NSMutableArray new];
NSMutableArray *testObjs = [NSMutableArray array];
NSData *data = [stringData dataUsingEncoding: NSUTF8StringEncoding];
NSMutableSet *testSet;

Expand Down
17 changes: 11 additions & 6 deletions Tests/base/NSPersonNameComponentsFormatter/basic.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ int main()
{
START_SET("NSPersonNameComponentsFormatter base");

NSPersonNameComponents *pnc = [[NSPersonNameComponents alloc] init];
NSPersonNameComponents *pnc;
NSPersonNameComponents *pnc2;
NSPersonNameComponentsFormatter *fmt;

pnc = AUTORELEASE([[NSPersonNameComponents alloc] init]);
[pnc setGivenName: @"Gregory"];
[pnc setMiddleName: @"John"];
[pnc setFamilyName: @"Casamento"];
[pnc setNameSuffix: @"PhD"];
[pnc setNamePrefix: @"Dr."];

NSPersonNameComponentsFormatter *fmt = [[NSPersonNameComponentsFormatter alloc] init];
NSPersonNameComponents *pnc2 = [fmt personNameComponentsFromString:
@"Dr. Gregory John Casamento PhD"];
fmt = AUTORELEASE([[NSPersonNameComponentsFormatter alloc] init]);
pnc2 = [fmt personNameComponentsFromString:
@"Dr. Gregory John Casamento PhD"];

PASS([[pnc givenName] isEqualToString:
[pnc2 givenName]], "First name matches");
PASS([[pnc middleName] isEqualToString:
Expand All @@ -27,7 +32,7 @@ int main()
PASS([[pnc namePrefix] isEqualToString:
[pnc2 namePrefix]], "Prefix name matches");

fmt = [[NSPersonNameComponentsFormatter alloc] init];
fmt = AUTORELEASE([[NSPersonNameComponentsFormatter alloc] init]);
pnc2 = [fmt personNameComponentsFromString:
@"Gregory John Casamento PhD"];
PASS([[pnc givenName] isEqualToString:
Expand All @@ -39,7 +44,7 @@ int main()
PASS([[pnc nameSuffix] isEqualToString:
[pnc2 nameSuffix]], "Suffix name matches");

fmt = [[NSPersonNameComponentsFormatter alloc] init];
fmt = AUTORELEASE([[NSPersonNameComponentsFormatter alloc] init]);
pnc2 = [fmt personNameComponentsFromString:
@"Gregory John Casamento"];
PASS([[pnc givenName] isEqualToString:
Expand Down
26 changes: 14 additions & 12 deletions Tests/base/NSPointerArray/create.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSMutableString *ms;
ENTER_POOL
NSString *val1, *val2, *val3;
NSPointerArray *obj, *old;
NSUInteger rc;
NSPointerArray *obj;
id vals[3];

val1 = @"Hello";
Expand All @@ -19,9 +17,9 @@ int main()
vals[1] = val2;
vals[2] = val3;

obj = [[NSPointerArray new] autorelease];
obj = AUTORELEASE([NSPointerArray new]);
PASS(obj != nil
&& [obj isKindOfClass:[NSPointerArray class]]
&& [obj isKindOfClass: [NSPointerArray class]]
&& [obj count] == 0,
"+new creates an empty pointer array");

Expand All @@ -36,13 +34,17 @@ int main()
PASS([obj count] == 5 && [obj pointerAtIndex: 2] == (void*)vals[0],
"+insertPointer:atIndex: works");

obj = [NSPointerArray pointerArrayWithWeakObjects];
ms = [@"hello" mutableCopy];
rc = [ms retainCount];
[obj addPointer: ms];
PASS(rc == [ms retainCount], "array with weak references doesn't retain");
LEAVE_POOL

ENTER_POOL
NSPointerArray *pa = [NSPointerArray weakObjectsPointerArray];
NSMutableString *ms = AUTORELEASE([@"hello" mutableCopy]);
NSUInteger rc = [ms retainCount];

[pa addPointer: ms];
PASS(rc == [ms retainCount], "array with weak references doesn't retain")
LEAVE_POOL

[arp release]; arp = nil;
return 0;
}

0 comments on commit c7f0c27

Please sign in to comment.