malt icon indicating copy to clipboard operation
malt copied to clipboard

Wrappers for custom allocators

Open fcoiffie opened this issue 6 years ago • 3 comments

Is it possible to catch and to track calls to custom allocators (malloc()/free() like functions) (for detecting memory leaks) ?

In my specific case, I'm using DPDK which provides its own memory management functions (https://doc.dpdk.org/api/rte__malloc_8h.html). For this kind of heavy load application, Valgrind is unusable. MALT seems to work with my application for usual malloc()/free() but I would like to extend its use to the custom allocator.

fcoiffie avatar Feb 12 '19 21:02 fcoiffie

Hi, yes we can make it without too much work, this is a really interesting use case.

I had the question at FOSDEM in the audience (maybe that's you ;)).

Will do somthing.

So I would think you have somehting like my_malloc()/my_free() inside your projet and I can find a way to intercept and redirect onto my malloc tracking.

I just need a clean way to pass as parameter to build a libray in flight or give hints to do your own by hand. That would match your expectation ?

Also, your internal alloc is inside a .so file ? Or built-in directly your executable ? For second case you will need to at least link a dedicated .so file pointing malt or just providing override capability on your funcitons.

svalat avatar Feb 18 '19 11:02 svalat

Hi,

I didn't attend FOSDEM but glad to know that someone else has the same needs.

As we link the allocation library statically with our executable, I think will have to modify the implementation itself (or use a little wrapper) but it's not a real problem.

fcoiffie avatar Feb 19 '19 15:02 fcoiffie

Ok, thanks for details. So I will first provide functions you can call by linking a fake lib to your code or something similar. That might be fine for a first try then I will look on more automatic interception of allocators in .so files.

svalat avatar Feb 21 '19 23:02 svalat

This is now done by providing some options on the malt command :

malt --wrap malloc:je_malloc,free:je_free ./prgm

Or more generic to wrap all the memoy managment function under a given prefix:

malt --wrap-prefix je_ ./prgm

You can wrap several prefix or set of function.

The only limitation is that you will not distinguish them from standard malloc in the final profile.

svalat avatar Dec 07 '22 23:12 svalat