malloc: *** error: incorrect checksum for freed object - object was probably modified after being freed

99,046

Solution 1

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

Solution 2

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.

Solution 3

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.

Share:
99,046

Related videos on Youtube

Sahil Kapoor
Author by

Sahil Kapoor

<3 Swift

Updated on March 29, 2020

Comments

  • Sahil Kapoor
    Sahil Kapoor about 4 years

    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.

    • Hot Licks
      Hot Licks over 10 years
      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?)
    • This isn't my real name
      This isn't my real name over 10 years
      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.
    • Admin
      Admin over 10 years
      It's a C++ library an the project it's MRC.
    • Geremia
      Geremia over 8 years
      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.
    • korgx9
      korgx9 about 6 years
      Try just clean the project CMD+SHIFT+K. it helped :)
  • R.. GitHub STOP HELPING ICE
    R.. GitHub STOP HELPING ICE over 10 years
    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.
  • user1118321
    user1118321 over 10 years
    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.
  • This isn't my real name
    This isn't my real name over 10 years
    Fourth possible cause: Writing past the end of an allocated block into another, currently-unallocated block.
  • Greg Parker
    Greg Parker over 10 years
    If Zombies don't catch anything then Guard Malloc may be able to help.
  • sudo
    sudo about 10 years
    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.
  • MBulli
    MBulli over 9 years
    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/…
  • Jerfov2
    Jerfov2 over 8 years
    The 3rd scenario is what got me in my C program. I called free() on a pointer used by getline(), but used it again afterwards. (by getline())
  • onmyway133
    onmyway133 about 8 years
    dyld: could not load inserted library '/usr/lib/libgmalloc.dylib' because image not found
  • arcady bob
    arcady bob almost 8 years
    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.
  • bianbian
    bianbian almost 6 years
    another possibility: like malloc(-2013003776), should malloc(ntohl(-2013003776))
  • SPlatten
    SPlatten over 3 years
    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.