54

I have a big problem with my iOS App: it crashes sometimes without detailed debug error. The stack trace is empty. These are the only two lines in the stack trace:

  1. crash start in UIApplicationMain at "symbol stub for: -[_UIHostedTextServiceSession dismissTextServiceAnimated:]".
  2. and report "libsystem_c.dylib`malloc_error_break".

in com.apple.main-thread.

The error on Xcode debugger (with connected device):

malloc: *** error for object 0x208a7614: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug

I have set a breakpoint in malloc_error_break with libsystem_c.dylib without any feedback from debugger. I have no idea to solve this issue.

5
  • 1
    This is hard. You basically have to inspect the code to find the problem. If you can figure out what kind of object is involved, that helps a lot. (BTW, ARC or manual reference counting?)
    – Hot Licks
    Nov 7, 2013 at 18:41
  • I'm pretty sure the only utility of setting a breakpoint in malloc_error_break is that it'll give you a chance to look at the corrupted freed object, and the content of the memory may help you trace the point where you're overwriting it. Nov 7, 2013 at 19:45
  • It's a C++ library an the project it's MRC.
    – user2776543
    Nov 8, 2013 at 7:48
  • My friend compiled my C code on a Mac, and it gave this error on runtime. However, it compiled and ran just fine on Linux. It seems to be a Mac-specific issue.
    – Geremia
    Feb 2, 2016 at 21:05
  • Try just clean the project CMD+SHIFT+K. it helped :)
    – korgx9
    Apr 26, 2018 at 6:56

5 Answers 5

52

To find the source of the problem, in Xcode go to Product > Scheme > Edit Scheme, and under Diagnostics tab enable all the Malloc settings and Guard Malloc.

With that, run your application again, and Xcode will stop at the line causing the problem.

Scheme definition

4
  • 20
    It's worth pointing out that Guard Malloc is only available in the simulator and not on a real device. See: developer.apple.com/library/ios/documentation/Performance/…
    – MBulli
    Jan 20, 2015 at 23:19
  • 2
    dyld: could not load inserted library '/usr/lib/libgmalloc.dylib' because image not found
    – onmyway133
    May 3, 2016 at 14:02
  • 1
    Enable Guard Malloc worked for me although it's worth noting that it appeared to slow down the simulator significantly, thus I would only turn it on when debugging an actual issue.
    – arcady bob
    Jul 4, 2016 at 22:32
  • I'm using macOS Big Sur 11.1, Xcode 12.3, when I tried Xcode, Product > Scheme > Edit Scheme, nothing happens, I've tried several times, even rebooted then tried again, same again, nothing happens.
    – SPlatten
    Dec 30, 2020 at 15:49
30

Since you're in the debugger, you should look at the memory location 0x208a7614 and see what's there. The data in memory may be helpful in figuring out what's going wrong.

What's happening is one of the following:

  1. you are freeing an object twice,

  2. you are freeing a pointer that was never allocated

  3. you are writing through an invalid pointer which previously pointed to an object which was already freed

Since the stack trace is coming up empty, it might be useful to add some debugging log statements to your code at various places to see if you can narrow down where in the code the problem lies. Using the memory tools in Instruments might also help. You could try turning on NSZombies, but this looks like a C allocation problem and not an Objective-C one.

Also, is anything else written to the console before the crash? If so, it may point you to where the problem is coming from.

7
  • 1
    There's a third possibility suggested by the error message: OP is writing through an invalid pointer which previously pointed to an object which was already freed. Nov 7, 2013 at 16:32
  • Ah, good point. I was thinking the error was displaying on a call to free(), but it's on a call to malloc(). Good catch. I'll update the text to reflect that. Nov 7, 2013 at 18:09
  • 12
    Fourth possible cause: Writing past the end of an allocated block into another, currently-unallocated block. Nov 7, 2013 at 19:43
  • 1
    If Zombies don't catch anything then Guard Malloc may be able to help. Nov 7, 2013 at 20:52
  • This answer is what saved me in my C program. I had accidentally allocated too small of an array to hold a sprintf result somewhere else in my code. Checking the memory address told me exactly which was the offending string because I was able to recognize its content.
    – sudo
    Apr 26, 2014 at 21:29
2

hi guys i have found this solution if you are using nib or xib interface and you facing this problem when you want to push a viewcontroller object then some time this error will occur and your app will be crash (specially error in iPad) Here is the solution:

// Format like this

UINavigationController *nav=[[UINavigationController      alloc]initWithRootViewController:yourViewControllerObj];

[self.navigationController  presentViewController:nav animated:true completion:nil];

Don't try to push in this condition.

0

If you have this problem. go to: product->scheme->diagnosis-> then enable mollic gaurd edge and zombie object then close then go product->stop then again product-build and run. best ofluck

0

I' am having the same issue.

I have a macOS 2015, big sur 11.7.

It all started when I updated my xcode. It seems that the last xcode version available for big sur has some bugs.

The fortran code that calls c++ and python plots was not running

I downgrade the xcode to 12.5, and the comand line tool for the this xcode version, but still have the same problem.

And it is intermitent. Some times code generate the error and sometimes not...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy