From c91be786f55636b91a01509f2091bcb4c53ffacb Mon Sep 17 00:00:00 2001 From: Rasmus Sten Date: Wed, 23 May 2012 21:20:26 +0300 Subject: [PATCH] Fix issues reported by static analysis (mostly memory management) --- Palvelukartta.h | 3 +-- Palvelukartta.m | 15 ++++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Palvelukartta.h b/Palvelukartta.h index 845e0ad..a517edd 100644 --- a/Palvelukartta.h +++ b/Palvelukartta.h @@ -9,7 +9,6 @@ #import "PalvelukarttaDelegate.h" #define PK_SERVICE_PUBLIC_TOILETS 8920 -#define PK_BASE_URL "http://localhost/palvelukarttaws/rest/v1/" #define PK_BASE_URL "http://www.hel.fi/palvelukarttaws/rest/v1/" #define DLOG(...) if (self.debug) NSLog(__VA_ARGS__); @@ -35,7 +34,7 @@ - (void) loadUnit:(NSNumber*) unitId; - (void) cancelAll; - (int) connectionsPending; -- (NSURLConnection*) doConnection:(NSURL*) url; +- (NSURLConnection*) newConnection:(NSURL*) url; + (NSString*) localizedStringForProperty:(NSString*) property inUnit:(NSDictionary*) unit; + (NSArray*) sortedServices:(NSArray*) list; diff --git a/Palvelukartta.m b/Palvelukartta.m index d5c26e8..7e744cd 100644 --- a/Palvelukartta.m +++ b/Palvelukartta.m @@ -55,11 +55,12 @@ - (void) cancelAll { - (void) loadUnit:(NSNumber*) unitIdObj { int unitId = [unitIdObj intValue]; NSURL *uniturl = [NSURL URLWithString:[NSString stringWithFormat:@"%@unit/%d", pkRestURL, unitId]]; - NSURLConnection *c = [self doConnection:uniturl]; + NSURLConnection *c = [self newConnection:uniturl]; [unitForConnection setValue:[NSNumber numberWithInt:unitId] forKey:ctostr(c)]; + [c release]; } -- (NSURLConnection*) doConnection:(NSURL*) url { +- (NSURLConnection*) newConnection:(NSURL*) url { NSURLRequest *req = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:req delegate:self]; [urlForConnection setValue:url forKey:ctostr(connection)]; @@ -70,14 +71,14 @@ - (NSURLConnection*) doConnection:(NSURL*) url { - (void) loadAllServices { NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@service/", pkRestURL]]; - servicesListConnection = [self doConnection:url]; + servicesListConnection = [self newConnection:url]; } - (void) loadServices:(int) ofType { NSURL *unitlisturl = [NSURL URLWithString:[NSString stringWithFormat:@"%@service/%d", pkRestURL, ofType]]; DLOG(@"Requesting service URL %@", unitlisturl); - listConnection=[self doConnection:unitlisturl]; + listConnection=[self newConnection:unitlisturl]; } - (void)connectRetry:(NSTimer*)theTimer @@ -85,7 +86,7 @@ - (void)connectRetry:(NSTimer*)theTimer NSURLConnection *connection = theTimer.userInfo; DLOG(@"retrying connection %@", connection); NSNumber *unitId = [unitForConnection valueForKey:ctostr(connection)]; - NSURLConnection *newConnection = [self doConnection:[urlForConnection valueForKey:ctostr(connection)]]; + NSURLConnection *newConnection = [self newConnection:[urlForConnection valueForKey:ctostr(connection)]]; [unitForConnection setValue:unitId forKey:ctostr(newConnection)]; [unitForConnection removeObjectForKey:ctostr(connection)]; [urlForConnection removeObjectForKey:ctostr(connection)]; @@ -98,6 +99,7 @@ - (void)connectRetry:(NSTimer*)theTimer } [attemptsForConnection removeObjectForKey:ctostr(connection)]; [attemptsForConnection setValue:count forKey:ctostr(newConnection)]; + [newConnection release]; } @@ -172,7 +174,6 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection DLOG(@"connectionDidFinishLoading but data buffer is empty for %@ (URL: %@)", ctostr(connection), [urlForConnection valueForKey:ctostr(connection)]); [self connection:connection didFailWithError:[NSError errorWithDomain:@"nu.dll.sv.empty-reply-error" code:1 userInfo:nil]]; - [data release]; [parser release]; [dataForConnection removeObjectForKey:ctostr(connection)]; [remainingConnections removeObject:connection]; @@ -204,7 +205,6 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection [NSException raise:@"unexpected" format:@"Connection not recognized: %@", connection]; } } - [data release]; [parser release]; [dataForConnection setValue:nil forKey:ctostr(connection)]; [remainingConnections removeObject:connection]; @@ -226,6 +226,7 @@ - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLRespon } else { data = [[NSMutableData alloc] init]; [dataForConnection setValue:data forKey:ctostr(connection)]; + [data release]; //NSLog(@"created new data buffer for connection %@", ctostr(connection)); }