[lttng-dev] [PATCH lttng-ust] Add trace support for calloc and realloc.

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Fri Aug 2 21:18:41 EDT 2013


* Alexander Monakov (amonakov at ispras.ru) wrote:
> On Thu, Aug 1, 2013 at 9:28 PM, Stefan Seefeld
> <stefan_seefeld at mentor.com> wrote:
> > I don't think any of this works. The ultimate problem is the one Jérémie
> > reported initially: dlsym will eventually call free() on the memory
> > calloc() returned, so my calloc fallback needs to return something that
> > can actually be freed.
> 
> I pointed out how free() will be safe specifically:
> 
> >> dlsym stores pointer to calloc'ed buffer, overwriting the pointer to mmap'ed
> >> buffer, completing initialization for the second time and making the
> >> subsequent free() safe.
> 
> Besides, you're intercepting free() in your LD_PRELOAD module as well,
> so you can just catch attempts to free your mmap'ed buffers there and
> munmap them safely.

Hello!

I'm now back from vacation :)

Please have a look at my implementation of quick and dirty malloc/free
tracker here:

https://github.com/efficios/memleak-finder

file: memleak-finder.c

Implementing a work-around for calloc vs dlsym was indeed tricky. The
solution I got there works fine so far (static array used for this
special-case). I think we might get the free() case to be more solid by
checking if the address being freed is in the static buffer range.

If you could submit a patch that improves memleak-finder.c to get this
right, it would be very much appreciated.

Then, I recommend porting the code from memleak-finder.c to UST
liblttng-ust-libc-wrapper. The approach I used in memleak-finder.c seems
to work quite well, and is clearly more complete that what we find in
liblttng-ust-libc-wrapper currently.

Thanks!

Mathieu 

> 
> Alexander
> 
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com



More information about the lttng-dev mailing list