0

I'm suddenly getting weird Malloc errors in my code such as:

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

It seems that they are random and just appear in different places when I set break points. I'm on XCode 8.1. Swift 3.0. Has anyone come across this?

I set the breakpoint and I get this:

libsystem_malloc.dylib`malloc_error_break:
->  0x112fa4760 <+0>:  pushq  %rbp
    0x112fa4761 <+1>:  movq   %rsp, %rbp
    0x112fa4764 <+4>:  nop    
    0x112fa4765 <+5>:  nopl   (%rax)
    0x112fa4769 <+9>:  popq   %rbp
    0x112fa476a <+10>: retq   

2 Answers 2

4

The most common cause of this error is threading violations. For example, if one thread performs the final release on an object and begins to deallocate it, and then another thread which has an unowned (Swift) or assign (ObjC) reference to the object modifies it, that will trigger this error. (It should not be possible to get this error if all references are strong or weak, since it shouldn't be possible for the object to be deallocated in the former case, and weak references are thread-safe in the latter case.)

It's of course possible that this is exposing a bug in the latest SDK (and so you should open a radar), but it is more typical that it's a bug in your code that changes in timing have caused to manifest. As noted, you should set a symbolic breakpoint on malloc_error_break to find out what object is in question.

Sign up to request clarification or add additional context in comments.

5 Comments

How do I set this breakpoint? Do I set it where the marker appears in the code after the crash?
It's a symbolic breakpoint. In the Breakpoints tab, click "+" and select "Symbolic Breakpoint." It fires anytime a function of that name is called.
Correct; that's what the message "*** set a breakpoint in malloc_error_break to debug" is telling you.
set the breakpoint and I posted the result in the question above. Not sure what the meaning is..
You likely still have a stack trace that shows you at what point the object is being deallocated. This often gives a hint as to what the object is (and you can select different stack frames to explore). malloc_error_break itself doesn't do anything; it's just a place to put a breakpoint. And of course you should also audit any places you may have unowned references and make sure those objects aren't manipulated on multiple threads.
0

It happens due to freeing an object twice or freeing a pointer that was never allocated or writing through an invalid pointer which previously pointed to an object which was already freed.

Try Product > Scheme > Edit Scheme, and under Diagnostics tab enable all the Malloc settings and Guard Malloc.(This option is only available in simulator)

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.