What could cause this difference in behaviour from iphone OS3.0 to iOS4.0?

Posted by frankodwyer on Stack Overflow See other posts from Stack Overflow or by frankodwyer
Published on 2010-06-09T23:57:14Z Indexed on 2010/06/10 0:02 UTC
Read the original article Hit count: 388

Filed under:
|
|

I am getting a strange EXC_BAD_ACCESS error when running my app on iOS4. The app has been pretty solid on OS3.x for some time - not even seeing crash logs in this area of the code (or many at all) in the wild.

I've tracked the error down to this code:

main class:

- (void) sendPost:(PostRequest*)request {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    NSURLResponse* response;
    NSError* error;
    NSData *serverReply = [NSURLConnection sendSynchronousRequest:request.request returningResponse:&response error:&error];

    ServerResponse* serverResponse=[[ServerResponse alloc] initWithResponse:response error:error data:serverReply]; 

    [request.objectToNotifyWhenDone performSelectorOnMainThread:request.targetToNotifyWhenDone withObject:serverResponse waitUntilDone:YES];

    [pool drain];
}

(Note: sendPost is run on a separate thread for each invocation of it. PostRequest is just a class to encapsulate a request and a selector to notify when complete)

ServerResponse.m:

@synthesize response;
@synthesize replyString;
@synthesize error;
@synthesize plist;

- (ServerResponse*) initWithResponse:(NSURLResponse*)resp error:(NSError*)err data:(NSData*)serverReply {
    self.response=resp;
    self.error=err;
    self.plist=nil;
    self.replyString=nil;

    if (serverReply) {
        self.replyString = [[[NSString alloc] initWithBytes:[serverReply bytes] length:[serverReply length] encoding: NSASCIIStringEncoding] autorelease];
        NSPropertyListFormat format;
        NSString *errorStr;
        plist = [NSPropertyListSerialization propertyListFromData:serverReply mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&errorStr];
    }

    return self;
}

ServerResponse.h:

@property (nonatomic, retain) NSURLResponse* response;
@property (nonatomic, retain) NSString* replyString;
@property (nonatomic, retain) NSError* error;
@property (nonatomic, retain) NSDictionary* plist;

- (ServerResponse*) initWithResponse:(NSURLResponse*)response error:(NSError*)error data:(NSData*)serverReply;

This reliably crashes with a bad access in the line:

self.error=err;

...i.e. in the synthesized property setter!

I'm stumped as to why this should be, given the code worked on the previous OS and hasn't changed since (even the binary compiled with the previous SDK crashes the same way, but not on OS3.0) - and given it is a simple property method.

Any ideas? Could the NSError implementation have changed between releases or am I missing something obvious?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about cocoa-touch