Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glibc's '-lmcheck' option and multithreading

We've been trying to hunt down some heap corruption issues in our multi-threaded C++ apps. As one technique, we tried add -lmcheck to the libraries line of the application. This is causing the app to crash out with apparent heap corruption in relatively short order.

Our app does use both malloc/free and new/delete (as appropriate).

One of our team wondered if -lmcheck was in fact thread safe, and put a mutex around all malloc/free calls. The crashes went away.

Does anyone know if -lmcheck is supposed to support multi-threading? I wonder if we just mis-understand the tool we're trying to use and thereby causing ourselves unneeded worry.

like image 257
Michael Kohne Avatar asked Nov 24 '08 18:11

Michael Kohne


2 Answers

No, mcheck is not thread-safe and should not be used with multi-threaded applications. Doing so can introduce additional problems since there is no synchronization between the threads. Here is the response from Ulrich Drepper (glibc maintainer) on the subject a few months ago:

mcheck does not work for multi-threaded code. It cannot possibly do. There is no way to fix this with the technology underlying mcheck.

like image 117
Robert Gamble Avatar answered Nov 13 '22 15:11

Robert Gamble


I should have checked that before we spent time fooling with it. Ahh well.

Here's the link to where that quote comes from (I believe):

http://sourceware.org/bugzilla/show_bug.cgi?id=6547

glibc documentation defect:

http://sourceware.org/bugzilla/show_bug.cgi?id=12751

has been opened to help avoid others from hitting this.

like image 42
Michael Kohne Avatar answered Nov 13 '22 15:11

Michael Kohne