Fix over-release.

Add autorelease around the Preferences methods.
This commit is contained in:
C.W. Betts 2017-06-03 22:53:10 -06:00 committed by sa666666
parent 1ecb8852de
commit b489a61e03
2 changed files with 11 additions and 6 deletions

View File

@ -45,23 +45,26 @@ static Preferences *sharedInstance = nil;
- (id)init - (id)init
{ {
if (self = [super init]) {
defaults = [NSUserDefaults standardUserDefaults]; defaults = [NSUserDefaults standardUserDefaults];
sharedInstance = self; sharedInstance = self;
}
return(self); return(self);
} }
- (void)setString:(const char *)key : (const char *)value - (void)setString:(const char *)key : (const char *)value
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString* theKey = [NSString stringWithCString:key encoding:NSASCIIStringEncoding]; NSString* theKey = [NSString stringWithCString:key encoding:NSASCIIStringEncoding];
NSString* theValue = [NSString stringWithCString:value encoding:NSASCIIStringEncoding]; NSString* theValue = [NSString stringWithCString:value encoding:NSASCIIStringEncoding];
[defaults setObject:theValue forKey:theKey]; [defaults setObject:theValue forKey:theKey];
[theKey release]; [pool release];
[theValue release];
} }
- (void)getString:(const char *)key : (char *)value : (int)size - (void)getString:(const char *)key : (char *)value : (int)size
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString* theKey = [NSString stringWithCString:key encoding:NSASCIIStringEncoding]; NSString* theKey = [NSString stringWithCString:key encoding:NSASCIIStringEncoding];
NSString* theValue = [defaults objectForKey:theKey]; NSString* theValue = [defaults objectForKey:theKey];
if (theValue != nil) if (theValue != nil)
@ -69,13 +72,14 @@ static Preferences *sharedInstance = nil;
else else
value[0] = 0; value[0] = 0;
[theKey release]; [pool release];
[theValue release];
} }
- (void)save - (void)save
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[defaults synchronize]; [defaults synchronize];
[pool release];
} }
@end @end

View File

@ -1283,6 +1283,7 @@
name = "«PROJECTNAMEASXML»"; name = "«PROJECTNAMEASXML»";
sourceTree = "<group>"; sourceTree = "<group>";
tabWidth = 2; tabWidth = 2;
usesTabs = 0;
}; };
29B97315FDCFA39411CA2CEA /* Other Sources */ = { 29B97315FDCFA39411CA2CEA /* Other Sources */ = {
isa = PBXGroup; isa = PBXGroup;