147

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

2
  • 1
    I solve this issue by disable safari inspect. stackoverflow.com/a/43885754/6521116
    – LF00
    May 10, 2017 at 7:18
  • 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.
    – Xofo
    Oct 10, 2018 at 18:52

5 Answers 5

156

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.

5
  • 2
    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).
    – Robert
    Aug 9, 2014 at 17:10
  • 1
    I'm not getting a plus button in the lower-left corner of the ⌘7 bar...Perhaps you meant ⌘8? Sep 23, 2019 at 21:07
  • 1
    @ScottyBlades guessing the shortcut has changed. I wrote this answer 8 years and 7 major Xcode versions ago... Sep 24, 2019 at 1:19
  • @AndrewMadsen No worries, just checking if it makes sense to edit. Sep 24, 2019 at 5:46
  • 1
    As of Xcode 12.4, you can get to it this way: Debug -> Breakpoints -> Create Synbolic Breakpoint (⌥ ⌘ \)
    – Datow King
    May 3, 2021 at 6:32
48

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...)

1
  • 11
    Looks like the module name is different in iOS, it's: libsystem_malloc.dylib. Breakpoint works for me without specifying a module.
    – Nestor
    Jan 6, 2014 at 10:05
8

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..

1
  • The space worked for me. I felt weird.
    – Owen Zhao
    Mar 6, 2022 at 22:23
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.

1
  • Thanks, this fixed my borked machine. Dec 11, 2014 at 15:18
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

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