On 2/28/2013 4:58 PM, John Reiser wrote:
>> Hi all, I'm wondering if it's possible for memcheck to show the last place
>> that some memory was accessible before being leaked.
> <snip>
>
> In your example below the difficulty lies in the code that has been elided
> by the ellipses "...". If there are any assignments of x to other pointers,
> or if x is passed as an actual argument of a function call, then it is hard
> to determine whether a leak occurs.
It could be done with reference counting, though this is of course
easier in more-constrained languages that do not allow (for example)
int *x = new int [256];
size_t x_ugly = (size_t) x;
double *x_uglier = (double *) x_ugly;
int *y = (int *) x_uglier;
I for one am glad that I am not trying to add this to memcheck.
Maybe it's just the domain I work in (electronic design automation),
where memory usage ebbs and flows and there are clearly defined
producers and consumers, but I don't ever recall needing this feature.
My code tends to be of the form "dispose of the object in the routine it
is created in, or else add it to the return value". This nested
responsibility means very little stuff gets lost, and it's pretty easy
to track down when leakage does occur.
I just finished cleaning up a multi-gigabyte program (135 K lines of new
code) that I wrote; it took about four runs of valgrind. Typical runs
can be six hours or more, so I wouldn't want to learn of a leak the hard
way. In a small run (15 minutes; six hours in valgrind) the initial
leakage was 22 Kbytes. All of the errors turned out to be local,
meaning the routine creating the object failed to dispose of it; I fixed
these and the 15-minute run is now leak-free.
This was helped by my XP-like development methodology; every module has
a standalone test program and I can run leak checks on these too.
>> int* g() {
>> int* x = new int[256]; <-- allocated here
>> ...
>> return x;
>> }
>>
>> int f() {
>> int* x = g();
>> ...
>> return 0; <-- leaked here
>> }
>>
--
David Chapman [email protected]
Chapman Consulting -- San Jose, CA
Software Development Done Right.
www.chapman-consulting-sj.com
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users