From be3a8ecc45306b547817d1b6573d63c89dcd747d Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Thu, 10 Feb 2011 12:11:03 +0000 Subject: [PATCH] leak fixing git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32035 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 12 ++++++++++++ Source/NSKeyValueObserving.m | 3 ++- Source/NSMessagePortNameServer.m | 4 +++- Source/NSNumberFormatter.m | 3 ++- Source/NSPathUtilities.m | 2 +- Source/NSSpellServer.m | 12 ++++++------ Source/NSString.m | 6 +++--- Source/NSURLProtocol.m | 4 ++-- Source/NSXMLParser.m | 4 +++- Tools/HTMLLinker.m | 4 ++-- 10 files changed, 36 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 08caa7e41..29dbbb88c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2011-02-10 Richard Frith-Macdonald + + * Source/NSSpellServer.m: Avoid compiler warning. + * Source/NSPathUtilities.m: + * Source/NSMessagePortNameServer.m: + * Source/NSKeyValueObserving.m: + * Source/NSURLProtocol.m: + * Source/NSString.m: + * Source/NSNumberFormatter.m: + * Source/NSXMLParser.m: + Fix memory leaks + 2011-02-10 11:02 David Chisnall * libs/base/trunk/Headers/Additions/GNUstepBase/GSMime.h, diff --git a/Source/NSKeyValueObserving.m b/Source/NSKeyValueObserving.m index 09372c54e..34dc1cc73 100644 --- a/Source/NSKeyValueObserving.m +++ b/Source/NSKeyValueObserving.m @@ -359,7 +359,7 @@ static NSString *newKey(SEL _cmd) u = uni_tolower(u); tmp = [[NSString alloc] initWithCharacters: &u length: 1]; [m replaceCharactersInRange: NSMakeRange(0, 1) withString: tmp]; - RELEASE(tmp); + [tmp release]; key = m; } return key; @@ -455,6 +455,7 @@ replacementForClass(Class c) tmp = [[NSString alloc] initWithCharacters: &u length: 1]; a[0] = [NSString stringWithFormat: @"set%@%@:", tmp, suffix]; a[1] = [NSString stringWithFormat: @"_set%@%@:", tmp, suffix]; + [tmp release]; for (i = 0; i < 2; i++) { /* diff --git a/Source/NSMessagePortNameServer.m b/Source/NSMessagePortNameServer.m index 10ef0cf8e..fc2fbac90 100644 --- a/Source/NSMessagePortNameServer.m +++ b/Source/NSMessagePortNameServer.m @@ -472,7 +472,9 @@ static void clean_up_names(void) RELEASE(a); } - [a addObject: [name copy]]; + name = [name copy]; + [a addObject: name]; + [name release]; [serverLock unlock]; [dl unlock]; diff --git a/Source/NSNumberFormatter.m b/Source/NSNumberFormatter.m index 16c4acd2d..fa6f6febb 100644 --- a/Source/NSNumberFormatter.m +++ b/Source/NSNumberFormatter.m @@ -950,7 +950,8 @@ static NSUInteger _defaultBehavior = 0; intPartRange.length++; } } - intPad = [[useFormat substringWithRange: intPartRange] mutableCopy]; + intPad = [[[useFormat substringWithRange: intPartRange] + mutableCopy] autorelease]; [intPad replaceOccurrencesOfString: defaultThousandsSeparator withString: @"" options: 0 diff --git a/Source/NSPathUtilities.m b/Source/NSPathUtilities.m index 21da7b1da..a44a167f4 100644 --- a/Source/NSPathUtilities.m +++ b/Source/NSPathUtilities.m @@ -1400,8 +1400,8 @@ ParseConfigurationFile(NSString *fileName, NSMutableDictionary *dict, if (wantVal == YES) { [dict setObject: @"" forKey: key]; - DESTROY(key); } + DESTROY(key); NSZoneFree(NSDefaultMallocZone(), src); NSZoneFree(NSDefaultMallocZone(), dst); return YES; diff --git a/Source/NSSpellServer.m b/Source/NSSpellServer.m index f97ac9705..12e4a81c5 100644 --- a/Source/NSSpellServer.m +++ b/Source/NSSpellServer.m @@ -44,6 +44,8 @@ NSString *const NSGrammarRange = @"NSGrammarRange"; NSString *const NSGrammarUserDescription = @"NSGrammarUserDescription"; NSString *const NSGrammarCorrections = @"NSGrammarCorrections"; +static NSConnection *spellServerConnection = nil; + /* User dictionary location */ static NSString *GNU_UserDictionariesDir = @"Dictionaries"; @@ -111,7 +113,6 @@ GSSpellServerName(NSString *vendor, NSString *language) byVendor: (NSString *)vendor { NSString *serverName = GSSpellServerName(vendor, language); - NSConnection *connection = nil; BOOL result = NO; if (serverName == nil) @@ -119,12 +120,11 @@ GSSpellServerName(NSString *vendor, NSString *language) return NO; } - connection = [[NSConnection alloc] init]; - if (connection) + spellServerConnection = [[NSConnection alloc] init]; + if (spellServerConnection) { - IF_NO_GC(RETAIN(connection);) - [connection setRootObject: self]; - result = [connection registerName: serverName]; + [spellServerConnection setRootObject: self]; + result = [spellServerConnection registerName: serverName]; } return result; diff --git a/Source/NSString.m b/Source/NSString.m index d8f29abab..016b4dd3b 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -125,6 +125,7 @@ static SEL cMemberSel = 0; #define IS_BIT_SET(a,i) ((((a) & (1<<(i)))) > 0) +static NSData *whitespaceBitmap; static unsigned const char *whitespaceBitmapRep = NULL; #define GS_IS_WHITESPACE(X) IS_BIT_SET(whitespaceBitmapRep[(X)/8], (X) % 8) @@ -133,7 +134,6 @@ static void setupWhitespace(void) if (whitespaceBitmapRep == NULL) { NSCharacterSet *whitespace; - NSData *bitmap; /* We can not use whitespaceAndNewlineCharacterSet here as this would lead @@ -143,8 +143,8 @@ static void setupWhitespace(void) whitespace = [NSCharacterSet characterSetWithCharactersInString: @" \t\r\n\f\b"]; - bitmap = RETAIN([whitespace bitmapRepresentation]); - whitespaceBitmapRep = [bitmap bytes]; + whitespaceBitmap = RETAIN([whitespace bitmapRepresentation]); + whitespaceBitmapRep = [whitespaceBitmap bytes]; } } diff --git a/Source/NSURLProtocol.m b/Source/NSURLProtocol.m index c98fe46b3..0247954ac 100644 --- a/Source/NSURLProtocol.m +++ b/Source/NSURLProtocol.m @@ -669,7 +669,7 @@ static NSURLProtocol *placeholder = nil; { NSMutableURLRequest *request; - request = [this->request mutableCopy]; + request = [[this->request mutableCopy] autorelease]; [request setURL: url]; [this->client URLProtocol: self wasRedirectedToRequest: request @@ -922,7 +922,7 @@ static NSURLProtocol *placeholder = nil; { NSMutableURLRequest *request; - request = [this->request mutableCopy]; + request = [[this->request mutableCopy] autorelease]; [request setURL: url]; [this->client URLProtocol: self wasRedirectedToRequest: request diff --git a/Source/NSXMLParser.m b/Source/NSXMLParser.m index 3cea32003..eba6c86b5 100644 --- a/Source/NSXMLParser.m +++ b/Source/NSXMLParser.m @@ -759,7 +759,8 @@ static SEL foundIgnorableSel; NSString *tmp; tmp = [[NSString alloc] initWithData: data encoding: enc]; - data = [[tmp dataUsingEncoding: NSUTF8StringEncoding] retain]; + this->data + = [[tmp dataUsingEncoding: NSUTF8StringEncoding] retain]; [tmp release]; } this->tagPath = [[NSMutableArray alloc] init]; @@ -1821,6 +1822,7 @@ NSLog(@"_processTag <%@%@ %@>", flag?@"/": @"", tag, attributes); c = cget(); if (c != '>') { + [attributes release]; return [self _parseError: @"" code: NSXMLParserGTRequiredError]; } diff --git a/Tools/HTMLLinker.m b/Tools/HTMLLinker.m index d056abc02..095506326 100644 --- a/Tools/HTMLLinker.m +++ b/Tools/HTMLLinker.m @@ -874,7 +874,7 @@ static int verbose = 0; NSString *filename; e = [HTMLDirectoryEnumerator alloc]; - e = [e initWithBasePath: pathOnDisk]; + e = [[e initWithBasePath: pathOnDisk] autorelease]; [e setReturnsAbsolutePaths: YES]; while ((filename = [e nextObject]) != nil) @@ -1056,7 +1056,7 @@ build_relocation_table_for_directory (NSString *dir) IF_NO_GC ([relocationTable autorelease];) e = [HTMLDirectoryEnumerator alloc]; - e = [e initWithBasePath: dir]; + e = [[e initWithBasePath: dir] autorelease]; /* The relocation table for a directory is relative to the directory top, so that the whole directory can be moved around without having to regenerate the .htmlink file. */