MCheck is a lightweight memory sanitizer similar to Valgrind. MCheck records heap memory consumption of an executable without needing to recompile by intercepting library calls to new and delete implemented in libstdc++.
- Designed to run on Linux operating systems (tested on Ubuntu 18.0.4) using the C++17 standard
- Untested on MacOS, but may work properly due to POSIX compliance
- Does not support Windows, and will not run properly due to lack of POSIX compliance
- Clone the git repository
git clone [email protected]:DavidPeet8/Memory-Sanitizer.git
- Change working directory to project root directory and run make
cd <project root> && make
- Run the sanitizer on an executable via
mcheck <exe to check path>
MCheck Flags:
-v
option indicates to use verbose realtime logging
Capabilities & Limitations:
- Provides detailed information on the history of a processes memory consumption, including order, size, and base address of all allocations and deallocations
- Due to lightweight implementation, line numbers and code snippets cannot be provided for detected memory leaks
- Currently cannot detect leaks in C style memory management or any memory allocation system calls
- Check that the created shared objects
libmcheck.so
andlibmcheckstorage.so
have been installed into~/mylibs
- Check that
mcheck
has been added to your$PATH
environment variable - If you are running mcheck in a context where DLL's must be installed at the system level (for example trying to profile with
perf
) run the following:
sudo mkdir /usr/lib/mcheck
sudo cp ~/mylibs/* .
sudo echo "/usr/lib/mcheck" >> /etc/ld.so.conf.d/.conf
sudo ldconfig
- Allow for the data collector to persist the allocation timeline to a swap file if the time line begins to hog memory as this may cause memory thrashing / constant state of paging
- Allow for additional options to be passed via POSIX message queue
- Shim C style memory mangement methods (malloc, calloc, realloc, free, etc)
- Look into possible ways of tracking / overloading memory allocation system calls (mmap, brk, etc)