Fix some more leaks

This commit is contained in:
rfm 2024-11-15 22:31:41 +00:00
parent 9573539795
commit 87c50830e2
5 changed files with 78 additions and 66 deletions

View file

@ -10,7 +10,8 @@ int main()
NSURL *url;
NSHTTPCookie *cookie;
TEST_FOR_CLASS(@"NSHTTPCookie", [NSHTTPCookie alloc],
cookie = AUTORELEASE([NSHTTPCookie new]);
TEST_FOR_CLASS(@"NSHTTPCookie", cookie,
"NSHTTPCookie +alloc returns an NSHTTPCookie");
dict = [NSDictionary dictionaryWithObjectsAndKeys: @"myname", @"Name",

View file

@ -116,7 +116,8 @@
return change;
}
- (NSString *)keypath {
- (NSString *) keypath
{
return _keypath;
}
@ -146,7 +147,11 @@
- (void) setInfo: (NSDictionary *)newInfo
{
ASSIGN(_info, [newInfo copy]);
if (newInfo != _info)
{
[_info release];
_info = [newInfo copy];
}
}
- (void *) context
@ -216,7 +221,7 @@
[_lock lock];
NSSet *paths = [[_changedKeypaths objectForKey:keypath] copy];
[_lock unlock];
return paths;
return AUTORELEASE(paths);
}
- (void)clear
{

View file

@ -3,10 +3,15 @@
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
test_alloc_only(@"NSKeyedArchiver");
test_NSObject(@"NSKeyedArchiver",[NSArray arrayWithObject:[[NSKeyedArchiver alloc] initForWritingWithMutableData: [NSMutableData data]]]);
test_NSObject(@"NSKeyedArchiver", [NSArray arrayWithObject:
AUTORELEASE([[NSKeyedArchiver alloc] initForWritingWithMutableData:
[NSMutableData data]])]);
test_alloc_only(@"NSKeyedUnarchiver");
test_NSObject(@"NSKeyedUnarchiver",[NSArray arrayWithObject:[[NSKeyedUnarchiver alloc] initForReadingWithData: [NSKeyedArchiver archivedDataWithRootObject: [NSData data]]]]);
test_NSObject(@"NSKeyedUnarchiver", [NSArray arrayWithObject:
AUTORELEASE([[NSKeyedUnarchiver alloc] initForReadingWithData:
[NSKeyedArchiver archivedDataWithRootObject: [NSData data]]])]);
[arp release]; arp = nil;
return 0;

View file

@ -11,14 +11,16 @@ int main()
id obj;
NSMutableData *data1;
obj = [NSKeyedArchiver alloc];
data1 = [NSMutableData dataWithLength: 0];
obj = [obj initForWritingWithMutableData: data1];
PASS((obj != nil && [obj isKindOfClass:[NSKeyedArchiver class]]), "-initForWritingWithMutableData seems ok");
obj = AUTORELEASE([[NSKeyedArchiver alloc]
initForWritingWithMutableData: data1]);
PASS((obj != nil && [obj isKindOfClass: [NSKeyedArchiver class]]),
"-initForWritingWithMutableData seems ok")
PASS_EXCEPTION([[NSUnarchiver alloc] initForReadingWithData:nil];,
PASS_EXCEPTION(AUTORELEASE([[NSUnarchiver alloc]
initForReadingWithData: nil]);,
@"NSInvalidArgumentException",
"Creating an NSUnarchiver with nil data throws an exception");
"Creating an NSUnarchiver with nil data throws an exception")
[arp release]; arp = nil;
return 0;

View file

@ -27,8 +27,9 @@ int main()
u = [NSURL URLWithString: @"http://www.w3.org/"];
ms = [NSMutableSet set];
[ms addObject: u];
data2 = [NSMutableData new];
archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData: data2];
data2 = [NSMutableData data];
archiver = AUTORELEASE([[NSKeyedArchiver alloc]
initForWritingWithMutableData: data2]);
[archiver setOutputFormat: NSPropertyListXMLFormat_v1_0];
[archiver encodeObject: ms forKey: @"root"];
[archiver finishEncoding];
@ -38,11 +39,8 @@ int main()
PASS([[[ms anyObject] absoluteString] isEqual: @"http://www.w3.org/"],
"Can archive and restore a URL");
[archiver release];
[data2 release];
PASS_RUNS(val1 = [NSString stringWithCString:"Archiver.dat"];
PASS_RUNS(
val1 = [NSString stringWithCString:"Archiver.dat"];
val2 = [NSString stringWithCString:"A Goodbye"];
val3 = [NSString stringWithCString:"Testing all strings"];
val4 = [NSNumber numberWithUnsignedInt: 100];
@ -50,7 +48,7 @@ int main()
arrayByAddingObject: val2]
arrayByAddingObject: val4];
vals2 = [vals1 arrayByAddingObject: val2];,
"We can build basic strings and arrays for tests");
"We can build basic strings and arrays for tests")
PASS([NSKeyedArchiver archiveRootObject: vals2 toFile: val1],
"archiveRootObject:toFile: seems ok");
@ -70,17 +68,18 @@ int main()
"unarchiveObjectWithFile: seems ok");
// encode
data2 = [[NSMutableData alloc] initWithCapacity: 10240];
archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData: data2];
data2 = [NSMutableData dataWithCapacity: 10240];
archiver = AUTORELEASE([[NSKeyedArchiver alloc]
initForWritingWithMutableData: data2]);
[archiver encodeObject: val3 forKey: @"string"];
[archiver finishEncoding];
// decode...
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData: data2];
s = [[unarchiver decodeObjectForKey: @"string"] retain];
unarchiver = AUTORELEASE([[NSKeyedUnarchiver alloc]
initForReadingWithData: data2]);
s = [unarchiver decodeObjectForKey: @"string"];
PASS((s != nil && [s isKindOfClass:[NSString class]] && [s isEqual: val3]),
"encodeObject:forKey: seems okay");
[data2 release];
NSLog(@"Original string: %@, unarchived string: %@",val3, s);