Skip to content

Commit

Permalink
Fix issues reported by static analysis
Browse files Browse the repository at this point in the history
(mostly memory management)
  • Loading branch information
pajp committed May 23, 2012
1 parent daeba00 commit c91be78
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
3 changes: 1 addition & 2 deletions Palvelukartta.h
Expand Up @@ -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__);
Expand All @@ -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;

Expand Down
15 changes: 8 additions & 7 deletions Palvelukartta.m
Expand Up @@ -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)];
Expand All @@ -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)];
Expand All @@ -98,6 +99,7 @@ - (void)connectRetry:(NSTimer*)theTimer
}
[attemptsForConnection removeObjectForKey:ctostr(connection)];
[attemptsForConnection setValue:count forKey:ctostr(newConnection)];
[newConnection release];

}

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand All @@ -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));

}
Expand Down

0 comments on commit c91be78

Please sign in to comment.