From 939fecc1870ab9a633abaa431422eedc3eaa5c55 Mon Sep 17 00:00:00 2001 From: Wolfgang Lux Date: Tue, 7 Feb 2012 09:22:40 +0000 Subject: [PATCH] Fix memory management bugs in Steptalk detected by clang's static analyzer git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/steptalk/trunk@34729 72102866-910b-0410-8b05-ffd578937521 --- ApplicationScripting/ChangeLog | 4 ++++ ApplicationScripting/Source/STTranscript.m | 2 ++ ChangeLog | 16 ++++++++++++++++ Frameworks/StepTalk/STBundleInfo.m | 2 +- Frameworks/StepTalk/STEnvironment.m | 1 + Frameworks/StepTalk/STEnvironmentDescription.m | 6 ++++-- Frameworks/StepTalk/STFileScript.m | 2 +- Frameworks/StepTalk/STObjCRuntime.m | 4 ++-- Languages/Smalltalk/ChangeLog | 6 ++++++ Languages/Smalltalk/STCompiledScript.m | 2 -- Languages/Smalltalk/STSmalltalkScriptObject.m | 1 + Tools/STExecutor.m | 1 + Tools/stalk.m | 3 +-- Tools/stenvironment.m | 4 +++- 14 files changed, 43 insertions(+), 11 deletions(-) diff --git a/ApplicationScripting/ChangeLog b/ApplicationScripting/ChangeLog index 9ecfed6..665f2f9 100644 --- a/ApplicationScripting/ChangeLog +++ b/ApplicationScripting/ChangeLog @@ -1,3 +1,7 @@ +2012-02-07 Wolfgang Lux + + * Source/STTranscript.m (-showError:): Fix space leak detected by clang. + 2012-01-15 Wolfgang Lux * Source/STScriptsPanel.m (-selectScript:): Validate Run button of the diff --git a/ApplicationScripting/Source/STTranscript.m b/ApplicationScripting/Source/STTranscript.m index e024346..4e72aee 100644 --- a/ApplicationScripting/Source/STTranscript.m +++ b/ApplicationScripting/Source/STTranscript.m @@ -134,6 +134,8 @@ static NSDictionary *normalTextAttributes; attributes:errorTextAttributes]; [textView insertText:astring]; + RELEASE(astring); + astring = [[NSAttributedString alloc] initWithString:@"\n" attributes:normalTextAttributes]; [textView insertText:astring]; diff --git a/ChangeLog b/ChangeLog index 32992dc..b7f7ef8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2012-02-07 Wolfgang Lux + + * Frameworks/StepTalk/STEnvironment.m (-registerObjectFinderNamed:): + * Frameworks/StepTalk/STEnvironmentDescription.m + (-updateFromDictionary:, -updateBehavioursFromDictionary:, + -updateClassWithName:description:): + * Frameworks/StepTalk/STFileScript.m (-source): + * Frameworks/StepTalk/STObjCRuntime.m (STAllObjectiveCSelectors): + * Tools/STExecutor.m (-executeScript:withArguments:): + * Tools/stalk.m (-createConversation, main): + * Tools/stenvironment.m (main): Fix potential space leaks detected + by clang. + + * Frameworks/StepTalk/STBundleInfo.m (+stepTalkBundleNames): Fix + double release detected by clang. + 2012-01-15 Wolfgang Lux * Frameworks/StepTalk/STStructure.h: diff --git a/Frameworks/StepTalk/STBundleInfo.m b/Frameworks/StepTalk/STBundleInfo.m index 6908918..bf264fd 100644 --- a/Frameworks/StepTalk/STBundleInfo.m +++ b/Frameworks/StepTalk/STBundleInfo.m @@ -82,7 +82,7 @@ static NSMutableDictionary *bundleInfoDict; [names addObject:name]; } - return AUTORELEASE([NSArray arrayWithArray:names]); + return [NSArray arrayWithArray:names]; } + stepTalkBundleWithName:(NSString *)moduleName diff --git a/Frameworks/StepTalk/STEnvironment.m b/Frameworks/StepTalk/STEnvironment.m index 92b0395..9241222 100644 --- a/Frameworks/StepTalk/STEnvironment.m +++ b/Frameworks/StepTalk/STEnvironment.m @@ -508,6 +508,7 @@ STEnvironment *sharedEnvironment = nil; } [self registerObjectFinder:finder name:name]; + [finder release]; } /** Remove object finder with name name */ diff --git a/Frameworks/StepTalk/STEnvironmentDescription.m b/Frameworks/StepTalk/STEnvironmentDescription.m index 935b8dd..0ec4754 100644 --- a/Frameworks/StepTalk/STEnvironmentDescription.m +++ b/Frameworks/StepTalk/STEnvironmentDescription.m @@ -157,7 +157,7 @@ static NSDictionary *dictForDescriptionWithName(NSString *defName) - (void)updateFromDictionary:(NSDictionary *)def { - NSAutoreleasePool *pool = [NSAutoreleasePool new]; + NSAutoreleasePool *pool; NSString *str; BOOL saveFlag = restriction; @@ -167,6 +167,7 @@ static NSDictionary *dictForDescriptionWithName(NSString *defName) return; }; + pool = [NSAutoreleasePool new]; str = [def objectForKey:@"DefaultRestriction"]; if(str) @@ -186,7 +187,6 @@ static NSDictionary *dictForDescriptionWithName(NSString *defName) [NSException raise:STGenericException format:@"Invalid default restriction rule '%@'.", str]; - return; } } @@ -317,6 +317,7 @@ static NSDictionary *dictForDescriptionWithName(NSString *defName) behInfo = [[STBehaviourInfo alloc] initWithName:name]; [behaviours setObject:behInfo forKey:name]; + [behInfo release]; [self updateBehaviour:behInfo description:[dict objectForKey:name]]; } @@ -389,6 +390,7 @@ static NSDictionary *dictForDescriptionWithName(NSString *defName) { class = [[STClassInfo alloc] initWithName:className]; [classes setObject:class forKey:className]; + [class release]; newClass = YES; } diff --git a/Frameworks/StepTalk/STFileScript.m b/Frameworks/StepTalk/STFileScript.m index fe66385..0fb9611 100644 --- a/Frameworks/StepTalk/STFileScript.m +++ b/Frameworks/StepTalk/STFileScript.m @@ -161,7 +161,7 @@ source = [[NSString alloc] initWithContentsOfFile:fileName]; } */ - return [[NSString alloc] initWithContentsOfFile:fileName]; + return [NSString stringWithContentsOfFile:fileName]; } /** Returns a script name by which the script is identified */ diff --git a/Frameworks/StepTalk/STObjCRuntime.m b/Frameworks/StepTalk/STObjCRuntime.m index fa1f829..d026aa4 100644 --- a/Frameworks/StepTalk/STObjCRuntime.m +++ b/Frameworks/StepTalk/STObjCRuntime.m @@ -260,7 +260,7 @@ NSArray *STAllObjectiveCSelectors(void) Method *methods; Class *classes; - array = [[NSMutableArray alloc] init]; + array = [NSMutableArray array]; numClasses = objc_getClassList(NULL, 0); classes = (Class *)NSZoneMalloc(STMallocZone, numClasses * sizeof(Class)); @@ -287,7 +287,7 @@ NSArray *STAllObjectiveCSelectors(void) NSZoneFree(STMallocZone, classes); /* get rid of duplicates */ - array = (NSMutableArray *)[[NSSet setWithArray:(NSArray *)array] allObjects]; + array = (NSMutableArray *)[[NSSet setWithArray:array] allObjects]; array = (NSMutableArray *)[array sortedArrayUsingSelector:@selector(compare:)]; return array; diff --git a/Languages/Smalltalk/ChangeLog b/Languages/Smalltalk/ChangeLog index b9f674f..5f2b109 100644 --- a/Languages/Smalltalk/ChangeLog +++ b/Languages/Smalltalk/ChangeLog @@ -1,3 +1,9 @@ +2012-02-07 Wolfgang Lux + + * STCompiledScript.m (-executedInEnvironment:): + * STSmalltalkScriptObject.m (-forwardInvocation:): + Fix potential space leak detected by clang. + 2012-01-15 Wolfgang Lux * STCompiledScript.m (+initialize, -executeInEnvironment:): Rename diff --git a/Languages/Smalltalk/STCompiledScript.m b/Languages/Smalltalk/STCompiledScript.m index 8831215..eff6e59 100644 --- a/Languages/Smalltalk/STCompiledScript.m +++ b/Languages/Smalltalk/STCompiledScript.m @@ -104,7 +104,6 @@ static SEL finalizeSelector; if(methodCount == 0) { NSLog(@"Empty script executed"); - return nil; } else if(methodCount == 1) { @@ -118,7 +117,6 @@ static SEL finalizeSelector; else if(![object respondsToSelector:mainSelector]) { NSLog(@"No 'main' method found"); - return nil; } else { diff --git a/Languages/Smalltalk/STSmalltalkScriptObject.m b/Languages/Smalltalk/STSmalltalkScriptObject.m index 0c7b497..fff43a9 100644 --- a/Languages/Smalltalk/STSmalltalkScriptObject.m +++ b/Languages/Smalltalk/STSmalltalkScriptObject.m @@ -163,6 +163,7 @@ if([methodName isEqualToString:@"exit"]) { [interpreter halt]; + [pool release]; return; } diff --git a/Tools/STExecutor.m b/Tools/STExecutor.m index 2167bcd..4e302c7 100644 --- a/Tools/STExecutor.m +++ b/Tools/STExecutor.m @@ -199,6 +199,7 @@ const char *STExecutorCommonOptions = /* Try to find it in standard script locations */ sm = [[STScriptsManager alloc] initWithDomainName:@"Shell"]; + AUTORELEASE(sm); script = [sm scriptWithName:file]; source = [script source]; diff --git a/Tools/stalk.m b/Tools/stalk.m index 04340e3..7395a98 100644 --- a/Tools/stalk.m +++ b/Tools/stalk.m @@ -112,8 +112,6 @@ return; } - RETAIN(env); - [env setObject:target forName:objectName]; conversation = [[STConversation alloc] initWithContext:env @@ -182,6 +180,7 @@ int main(int argc, const char **argv) NSLog(@"Warning: This tool is obsolete."); [executor runWithArguments:args]; + [executor release]; [pool release]; return 0; diff --git a/Tools/stenvironment.m b/Tools/stenvironment.m index 80489c4..c46d2bd 100644 --- a/Tools/stenvironment.m +++ b/Tools/stenvironment.m @@ -168,7 +168,9 @@ int main(int argc, const char **argv) { NSLog(@"Unable to register environment '%@'.", envIdentifier); } - + + RELEASE(connection); + RELEASE(envprocess); RELEASE(pool); return 0;