I have an automatic program checker installed, which allows to run some tests against (student) code with respect of memory and time limits. Currently all programs written in c++ are run in valgrind environment to expose memory allocation problems. As well known, valgrind significantly slows down program execution. But in many cases it does not matter because (student) programs in other languages (like java or python) have similar run time.

Unfortunately, I've run into a case when runtime of C++ increases significantly and I need faster drop-in replacement for valgrind.

I've some restrictions/abilities for tool:

  1. The tool should work at the start of the program (not to be attached after start).
  2. It should detect most memory allocation/leaks problems.
  3. The program should exit with some non-zero code if a problem with memory is detected.
  4. The source code can be preprocessed with some tool.
  5. It should be faster than valgrind.
  6. g++ or linux-only solutions are ok.

There is also and old similar question on SO: https://stackoverflow.com/questions/18455698/lightweight-memory-leak-debugging-on-linux But I have a bit different situation and solution there did not work for me.

I've tried:

  1. GNU libc built-in malloc debugging (with LD_PRELOAD) - no auto analysis, only log
  2. memleax - only allows to be attached to running program, minimum window is one second - too high.
  3. LeakTracer - seems like it, but no non-zero code (but I've already done a PR) and sometimes it has false positives
  4. bdwgc, but same problems with non-zero exit code and doesn't work without code editing (which may be non trivial for c++ stl containers).

This post was originally posted on StackOverflow, but deleted as offtopic.

1 Answer 1


I've ended up using address sanitizers packaged with gcc and clang.


  • You can accept your own answer, in order to help others who find this question in future
    – Mawg
    Oct 31, 2017 at 10:47
  • 1
    Yep, waiting for 24 hours to end.
    – ov7a
    Oct 31, 2017 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.