0

I'm using openURL to send an email w/some links. The function looks like this:

//
+ (void) sendEmail:(NSString *) subject withBody:(NSString *)body {
 NSString *mailString = [NSString stringWithFormat:@"mailto:?@&subject=%@&body=%@",
       [subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
       [body  stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailString]];
 [mailString autorelease];
 }

The code that calls this function looks like this:

[AppNameAppDelegate sendEmail:subjectLine withBody:bodyText];

No matter what the subjectLine and bodyText, I get an error like this:

Program received signal:  “EXC_BAD_ACCESS”.

The email actually pops up, so I know it's making it through that openURL. But by then I guess the program has crashed and so it is not restored when you exit the email pane.

Any ideas on why this is happening?

Issue looks like this but that answer isn't applicable. It looks more like this forum post but unfortunately that issue looks like it was never solved.

UPDATE: When removing the autoreleased mailString (per the instructions in the StackOverflow ticket mentioned above) it does not improve the situation.

//
+ (void) sendEmail:(NSString *) subject withBody:(NSString *)body {
 NSString *mailString = [NSString stringWithFormat:@"mailto:?@&subject=%@&body=%@",
       [subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
       [body  stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailString]];
 }

Setting a malloc_error_break breakpoint does not seem to do anything. The output still looks like this:

AppName(1424,0x3e9097c8) malloc: *** error for object 0x16fdf0: double free
*** set a breakpoint in malloc_error_break to debug

2 Answers 2

3
NSString *mailString = [NSString stringWithFormat:...

already returns autoreleased string - you must not sent any autorelease messages to it

4
  • Thank you for your answer. Unfortunately, I had tried this and it does not seem to solve my problem. Pls see updated question for output.
    – buley
    Aug 22, 2010 at 16:28
  • 1
    What system do you target? I've made a sample - code without extra autorelease seems to work fine on iPhoneOS 3.1... May be try to clean and rebuild your project? Or your real problem may be not in this function but somewhere else.
    – Vladimir
    Aug 22, 2010 at 16:53
  • I'm targeting 4.0. Unfortunately I guess the issue goes deeper than I can expect to find an answer for.
    – buley
    Aug 22, 2010 at 17:02
  • Try to review your code - may be there's more redundant (auto)releases... Especially in the functions that get called when application goes to the background
    – Vladimir
    Aug 22, 2010 at 17:12
1

Use NSZombieEnabled to debug as I described in this answer.

7
  • Thanks for the suggestion. Will work on this. But removing this code removes the error, suggesting to me that I can bet that the cause is somewhere in these few lines of code. Will verify using this technique.
    – buley
    Aug 22, 2010 at 16:33
  • Found my zombie. Any tips on how I figure out what that memory allocation represents? 2010-08-22 09:34:58.165 AppName[1448:307] *** -[CFString release]: message sent to deallocated instance 0x19a0f0
    – buley
    Aug 22, 2010 at 16:36
  • 1
    @editor: That means you're over-releasing a string somewhere. Check to make sure you're not making the same mistake anywhere else.
    – jtbandes
    Aug 22, 2010 at 16:37
  • 1
    @editor: With that redundant autorelease line now removed or not? Aug 22, 2010 at 16:38
  • The redundant autorelease is removed. In debugger, that memory assignment is filed under the variable $r10 without much more information.
    – buley
    Aug 22, 2010 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.