You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When dynamically loading leveldb's shared object, libtcmalloc (if enabled) is implicitly loaded too.
The loading of libtcmalloc overrides malloc, free and other libc functions.
This override is fine when it happens at the beginning of execution but causes 2 problems when it is late loaded (with dlopen after executable had started):
Memory previously allocated with malloc can be freed with tcmalloc, causing a crash
tcmalloc itself calls library code that may have already resolved its new/delete symbols to libc's whereas direct calls to new/delete in tcmalloc are always resolved to its own implementation.
To illustrate, compile&run this C++ program (fix the path to libleveldb)
#include<dlfcn.h>
#include<string>intmain() {
std::string s; // This fixes libstdc++ new/delete to use malloc/free. No crash without it!dlopen("/usr/lib/x86_64-linux-gnu/libleveldb.so", RTLD_NOW); // directly loading tcmalloc causes the same problemreturn0;
}
This bug had been hit many times, looks like:
[src/tcmalloc.cc:283] Attempt to free invalid pointer 0x562806a73fb0
I suggest removing tcmalloc references in leveldb. Document that it is recommended for use in the user application, instead. This will allow safe late-loading of leveldb.
The text was updated successfully, but these errors were encountered:
In some more detail, the crash often happens inside MallocExtension::Initialize(), in the code inside #ifdef __GLIBC__, so reproduction with the example program above is possible under Linux, but on macOS, for example, it doesn't cause a crash.
* Update with instructions to build under Visual Studio
Fixes Issue google#634.
I spent 3 days trying to build this library under Visual Studio 2017, only to discover on has to link to `Shlwapi.lib`.
Became so frustrated with the docs that I added full build instructions for Visual Studio 2015, 2017 and Intel Comiler 2015 and 2019.
* Update headings
When dynamically loading leveldb's shared object, libtcmalloc (if enabled) is implicitly loaded too.
The loading of libtcmalloc overrides
malloc
,free
and other libc functions.This override is fine when it happens at the beginning of execution but causes 2 problems when it is late loaded (with
dlopen
after executable had started):To illustrate, compile&run this C++ program (fix the path to libleveldb)
This bug had been hit many times, looks like:
commercialhaskell/stack#2926
https://stackoverflow.com/questions/50132801/debugging-a-failure-to-access-libleveldb-with-c-sharp-on-osx
junyanz/interactive-deep-colorization#26
lamdu/lamdu#104 (comment)
I suggest removing
tcmalloc
references inleveldb
. Document that it is recommended for use in the user application, instead. This will allow safe late-loading of leveldb.The text was updated successfully, but these errors were encountered: