From: Paul Floyd Date: Sun, 16 Jun 2024 19:11:33 +0000 (+0200) Subject: doc FAQ: add items for common code causes of 'Mismatched' errors X-Git-Tag: VALGRIND_3_24_0~110 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=022fc29d5ffb4e9cca0db6b197c48b0b02ac9005;p=thirdparty%2Fvalgrind.git doc FAQ: add items for common code causes of 'Mismatched' errors (when there is no fault in the code). --- diff --git a/docs/xml/FAQ.xml b/docs/xml/FAQ.xml index 414ac1364..4179a62ac 100644 --- a/docs/xml/FAQ.xml +++ b/docs/xml/FAQ.xml @@ -486,9 +486,62 @@ int main(void) - + + + Why does Memcheck report many + "Mismatched free() / delete / delete []" errors when + my code is correct? + + + There are two possible causes of this. + + First, check if you are using an optimized build of Google + tcmalloc (part of Google perftools). This library uses a single + alias for free/scalar delete/array delete as an unmeasurable + micro-optimization. There is simply no way for Memcheck to tell + which of these was originally used. There are a few possible + workarounds. + + + Build tcmalloc with "CPPFLAGS=-DTCMALLOC_NO_ALIASES" + (best). + + + Use a debug build of tcmalloc (debug builds turn off the alias + micro-optimization). + + + Do not link with tcmalloc for the builds that you use for + Memecheck testing. + + + + Second, if you are replacing operator new or operator delete + make sure that the compiler does not perform optimizations such as + inlining on calls to these functions. Such optimizations can + prevent Memcheck from correctly identifying the allocator or + deallocator that is being used. + + The following two code snippets show how you can do this with + GCC and LLVM (clang). + + + // GCC + void operator delete(void*) noexcept __attribute__((__externally_visible__)); + + + // LLVM (clang) + __attribute__((__visibility__("default"))) void operator delete(void*) noexcept; + + + If all else fails, you might have to use "--show-mismatched-frees=no" + + + + +