0

We write a shared library(say slib.so) which is dlopen'ed, used and dlclose'd in a never-ending executable. I want to check for memory leaks in the library slib.so without attaching the executable.

Is there any tool in Linux to find out the memory leaks in a shared library? So I need a tool which monitors the heap between dlopen and dlclose and report the issues after dlclose.

Srikanth
  • 517
  • 3
  • 10
  • 29

1 Answers1

0

I need a tool which monitors the heap between dlopen and dlclose and report the issues after dlclose.

Any of the standard leak detection tools will work: Valgrind, Leak Sanitizer, TCMalloc heap checker, etc.

All you need to do is write a trivial executable wrapper, something like:

#include <dlfcn.h>

int main()
{
  for (int j = 0; j < 10; j++) {
    void *h = dlopen("libslib.so", RTLD_NOW);
    // optionally exercise the library here.
    dlclose(h);
  }
}
Employed Russian
  • 199,314
  • 34
  • 295
  • 362