How to "set a breakpoint in malloc_error_break to debug"
Asked Answered
H

5

149

I'm getting lots of console outputs like this without my application crashing:

malloc: * error for object 0xc6a3970: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug

How can I find out which object or variable is affected?

I tried setting a symbolic breakpoint like this but it never halts:

enter image description here

Hokanson answered 26/12, 2012 at 19:24 Comment(2)
I solve this issue by disable safari inspect. https://mcmap.net/q/160552/-how-to-find-the-cause-of-a-malloc-quot-double-free-quot-errorAccra
One of the causes of this is a function/method which is supposed to return an object and it reaches the end of the function and does not return anything.Ayr
I
158

Set a breakpoint on malloc_error_break() by opening the Breakpoint Navigator (View->Navigators->Show Breakpoint Navigator or ⌘8), clicking the plus button in the lower left corner, and selecting "Add Symbolic Breakpoint". In the popup that comes up, enter malloc_error_break in the Symbol field, then click Done.

EDIT: openfrog added a screenshot and indicated that he's already tried these steps without success after I posted my answer. With that edit, I'm not sure what to say. I haven't seen that fail to work myself, and indeed I always keep a breakpoint on malloc_error_break set.

Incubus answered 26/12, 2012 at 19:31 Comment(5)
This worked for me (without the module). The cause of the issue for me was that I had a UIImage backed by a file, and I was overwriting the file with a different image. This caused an error when I called UIImagePNGRepresentation on the original image (not when the file was actually overwritten).Seabury
I'm not getting a plus button in the lower-left corner of the ⌘7 bar...Perhaps you meant ⌘8?Tashia
@Tashia guessing the shortcut has changed. I wrote this answer 8 years and 7 major Xcode versions ago...Incubus
@AndrewMadsen No worries, just checking if it makes sense to edit.Tashia
As of Xcode 12.4, you can get to it this way: Debug -> Breakpoints -> Create Synbolic Breakpoint (⌥ ⌘ \)Olericulture
F
49

In your screenshot, you didn't specify any module: try setting "libsystem_c.dylib"

enter image description here

I did that, and it works : breakpoint stops here (although the stacktrace often rise from some obscure system lib...)

Frederigo answered 3/9, 2013 at 13:49 Comment(1)
Looks like the module name is different in iOS, it's: libsystem_malloc.dylib. Breakpoint works for me without specifying a module.Faiyum
F
9

I had the same problem with Xcode. I followed steps you gave and it didn't work. I became crazy because in every forum I saw, all clues for this problem are the one you gave. I finally saw I put a space after the malloc_error_break, I suppressed it and now it works. A dumb problem but if the solution doesn't work, be sure you haven't put any space before and after the malloc_error_break.

Hope this message will help..

Fancie answered 19/4, 2013 at 8:55 Comment(1)
The space worked for me. I felt weird.Gastongastralgia
B
4

I had given permissions I shouldn't have to write in some folders (especially /usr/bin/), and that caused the problem. I fixed it by opening Disk Utility and running 'Repair Disk Permissions' on the Macintosh HD disk.

Beverlybevers answered 16/7, 2014 at 7:52 Comment(1)
Thanks, this fixed my borked machine.Picked
A
2

I solve it by close safari inspector. Refer to my post. I also found sound sometimes when I run my app for testing, then I open safari with auto inspector on, after this, I do some action in my app then this issue triggered.

enter image description here

Accra answered 10/5, 2017 at 7:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.