Skip to content
Browse files

Fix issues reported by static analysis

(mostly memory management)
  • Loading branch information...
1 parent daeba00 commit c91be786f55636b91a01509f2091bcb4c53ffacb @pajp committed May 23, 2012
Showing with 9 additions and 9 deletions.
  1. +1 −2 Palvelukartta.h
  2. +8 −7 Palvelukartta.m
View
3 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;
View
15 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,22 +71,22 @@ - (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
{
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));
}

0 comments on commit c91be78

Please sign in to comment.
Something went wrong with that request. Please try again.