Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obj-C: Memory Leak of Malloc 48 bytes in strdup frame

Tags:

In my app, I have am receiving multiple memory leaks. The object is Malloc 48 bytes, and it always originates from the responsible caller strdup. The history of the object only shows it being Malloced, and no other retains or releases. The stacktrace doesn't show any of my code. The only bits of relevance that I can pick out are:

  10 UIKit _UIGestureRecognizerSendActions
   9 UIKit -[UIScrollView handlePan:]
   8 UIKit -[UIScrollView _endPanWithEvent:]
   7 UIKit -[UIScrollView(Static) _startTimer:]
   6 CoreFoundation CFNotificationCenterAddObserver
   5 CoreFoundation _CFXNotificationRegisterObserver
   4 libnotify.dylib notify_register_dispatch
   3 libnotify.dylib notify_register_mach_port
   2 libnotify.dylib token_table_add
   1 libsystem_c.dylib strdup
   0 libsystem_c.dylib malloc

It seems to occur whilst scrolling on a map view, but I am unsure how to proceed as none of my code is referenced in the stack. How should I proceed in diagnosing this leak?

If any further information is required, please let me know.

Regards, Nick

like image 351
dark_perfect Avatar asked Mar 26 '12 21:03

dark_perfect


People also ask

Does malloc cause memory leak?

At the malloc() , new memory is allocated, but it is never assigned to a pointer. There is no way to keep track of the memory and no way to deallocate it; thus, we have a memory leak.

What is C memory leak?

The memory leak occurs, when a piece of memory which was previously allocated by the programmer. Then it is not deallocated properly by programmer. That memory is no longer in use by the program. So that place is reserved for no reason. That's why this is called the memory leak.

What is Memcheck?

Memcheck is a memory error detector. It can detect the following problems that are common in C and C++ programs. Accessing memory you shouldn't, e.g. overrunning and underrunning heap blocks, overrunning the top of the stack, and accessing memory after it has been freed.

How does valgrind Memcheck work?

Valgrind works by doing a just-in-time (JIT) translation of the input program into an equivalent version that has additional checking. For the memcheck tool, this means it literally looks at the x86 code in the executable, and detects what instructions represent memory accesses.


1 Answers

If it is "only" 48 bytes, all evidence points to frames in the system frameworks (i.e. the allocation is never exposed to your code), and there are not 10s of thousands of 'em, then I (a) wouldn't worry about it too much, but I would (b) immediately file a bug via http://bugreport.apple.com/

Attach a binary of your application and instructions as to how to reproduce the issue.

like image 200
bbum Avatar answered Nov 03 '22 01:11

bbum