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

openfrog
  • 40,201
  • 65
  • 225
  • 373
  • 1
    I solve this issue by disable safari inspect. http://stackoverflow.com/a/43885754/6521116 – LF00 May 10 '17 at 07: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 '18 at 18:52

5 Answers5

155

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.

Ramis
  • 13,985
  • 7
  • 81
  • 100
Andrew Madsen
  • 21,309
  • 5
  • 56
  • 97
  • 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 09 '14 at 17:10
  • 1
    I'm not getting a plus button in the lower-left corner of the `⌘7` bar...Perhaps you meant `⌘8`? – ScottyBlades Sep 23 '19 at 21:07
  • 1
    @ScottyBlades guessing the shortcut has changed. I wrote this answer 8 years and 7 major Xcode versions ago... – Andrew Madsen Sep 24 '19 at 01:19
  • @AndrewMadsen No worries, just checking if it makes sense to edit. – ScottyBlades Sep 24 '19 at 05:46
  • 1
    As of Xcode 12.4, you can get to it this way: Debug -> Breakpoints -> Create Synbolic Breakpoint (⌥ ⌘ \\) – Datow King May 03 '21 at 06: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...)

Vinzzz
  • 11,746
  • 5
  • 36
  • 42
  • 10
    Looks like the module name is different in iOS, it's: `libsystem_malloc.dylib`. Breakpoint works for me without specifying a module. – Nestor Jan 06 '14 at 10:05
7

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

pkamb
  • 33,281
  • 23
  • 160
  • 191
Sébastien
  • 321
  • 2
  • 10
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.

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

Community
  • 1
  • 1
LF00
  • 27,015
  • 29
  • 156
  • 295