Brennan Kastner
Brennan Kastner

Reputation: 1

Trying to trigger PHP script, get EXC_BAD_ACCESS

This below is my code, when it gets to the end of the function, the debugger throws an EXC_BAD_ACCESS error and when I check the website's logs, the url was never visited. If anyone could help me fix this issue, it would be greatly appreciated:

-(IBAction)submitEmail:(id)sender
{
    NSString *urlStringRaw = [[NSString alloc] init];
    urlStringRaw = [NSString stringWithFormat:@"http://vedev.org/AnonMail/sendEmail.php?from=%@&to=%@&subject=%@&body=%@", from.text, to.text, subject.text, bodyContent.text];
    NSString *urlString = [urlStringRaw stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [urlStringRaw release];
    NSURL * url = [NSURL URLWithString:urlString];
    [urlString release];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [url release];
    NSURLConnection *connection = [NSURLConnection connectionWithRequest:requestObj delegate:nil];
    [connection release];
    [requestObj release];   
}

Upvotes: 0

Views: 124

Answers (1)

Chris Hanson
Chris Hanson

Reputation: 55164

An EXC_BAD_ACCESS signal means your application has a memory-management error somewhere. It has nothing to do with the server side. This isn't too surprising since the code you posted above has numerous memory management errors.

You should run the static analyzer on your project - "Build and Analyze" in Xcode - and fix the errors it flags. Also, learn the standard Cocoa memory management rules; they'll show you exactly what you're doing wrong in the code you posted (and any other code in your application).

Also, it's important to understand what pointer variables actually are — references to objects, not the objects themselves. For example, you wrote this:

NSString *urlStringRaw = [[NSString alloc] init];
urlStringRaw = [NSString stringWithFormat:@"..."];

Why did you think you needed to write the first line the way you did?

Upvotes: 2

Related Questions