|
From: Dennis L. <pla...@in...> - 2005-09-23 16:37:49
|
Hi, I know that currently valgrind can only tell you where memory was allocated that is lost. In certain situations its hard to track down memory leaks with this information only, so like if the data is passed around to dozens of different parts in the program, and sometimes the correct parts destroys it and sometimes not. So, what would be a nice feature is, if valgrind could report the stacktrace for the position where the last pointer referencing the memory is lost. The question now is, if the memcheck tool can be (easily) get to track the pointers ? Im thinking of tracking whether copied around data is a pointer to something when copying it, and if the data gets unreachable (either through explicit deallocation, or implicit by reducing stack) then some reference counter for the allocated memory is decreased, and if 0 reported. If memcheck cannot be used for this, is there an estimate on how easy/hard it would be to create a new tool that does this (and only this) ? Or if its even possible with the valgrind framework ? greets Dennis |
|
From: Nicholas N. <nj...@cs...> - 2005-09-23 19:20:32
|
On Fri, 23 Sep 2005, Dennis Lubert wrote:
> I know that currently valgrind can only tell you where memory was
> allocated that is lost. In certain situations its hard to track down
> memory leaks with this information only, so like if the data is passed
> around to dozens of different parts in the program, and sometimes the
> correct parts destroys it and sometimes not.
> So, what would be a nice feature is, if valgrind could report the
> stacktrace for the position where the last pointer referencing the
> memory is lost. The question now is, if the memcheck tool can be
> (easily) get to track the pointers ? Im thinking of tracking whether
> copied around data is a pointer to something when copying it, and if the
> data gets unreachable (either through explicit deallocation, or implicit
> by reducing stack) then some reference counter for the allocated memory
> is decreased, and if 0 reported. If memcheck cannot be used for this, is
> there an estimate on how easy/hard it would be to create a new tool that
> does this (and only this) ? Or if its even possible with the valgrind
> framework ?
This paper describes such a scheme:
@InProceedings{Mae:precise2004,
author = {Jonas Maebe and Michiel Ronsse and Koen De Bosschere},
title = {Precise detection of memory leaks},
booktitle = {Proceedings of the Second International Workshop on
Dynamic
Analysis (WODA 2004)},
pages = {},
address = {Edinburgh, Scotland},
month = may,
year = 2004,
summary = {Dynamic leak detector. Notable in that it detects the
leaks when they happen. Does this by doing reference
counting on each block, and tracking extra information about
each pointer. When a pointer is copied or clobbered, the
counts are updated. Per-pointer-info is stored in a tree,
with one part for stack pointers and the other half for the
rest. Some minor complications are used to avoid false
positives, eg. caused by advancing a pointer past the start
of the block and then later back. Memory values are
shadowed, registers not, but registers are all checked
linearly when necessary (eg. when deciding whether a block
has leaked). Implemented in DIOTA, not surprisingly the
current version runs programs 200--300 times slower.}
}
I don't see how this can be done with acceptable performance. I'd be
happy to be proven wrong.
Nick
|