lkml.org 
[lkml]   [2015]   [Dec]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v5 02/14] perf tools: Prevent calling machine__delete() on non-allocated machine
Em Wed, Dec 16, 2015 at 09:37:18AM +0800, Wangnan (F) escreveu:
>
>
> On 2015/12/15 20:36, Jiri Olsa wrote:
> >On Mon, Dec 14, 2015 at 10:39:11AM +0000, Wang Nan wrote:
> >
> >SNIP
> >
> >>@@ -137,12 +138,15 @@ void machine__exit(struct machine *machine)
> >> void machine__delete(struct machine *machine)
> >> {
> >> machine__exit(machine);
> >>- free(machine);
> >>+ if (machine->allocated)
> >>+ free(machine);
> >>+ else
> >>+ pr_warning("WARNING: delete a non-allocated machine. Skip.\n");
> >we used WARN_ONCE several times already in similar cases
> >
> >jirka
>
> Will switch to:
>
> @@ -136,13 +138,13 @@ void machine__exit(struct machine *machine)
>
> void machine__delete(struct machine *machine)
> {
> - machine__exit(machine);

Better keep the above.

And I wonder if we would go on sprinkling these kinds of checks for all
classes we have :-\

I think this is a job for some static analisys tool, that or we figure
out a way to find out if an address is for a stack or heap and use that
instead, and in a bpf based tool, perhaps, one that would hook into all
*__delete() tools and check if the object it is using should or not be
in fact free()ed.

I could think about hooking __new*() calls, hashing the return value,
then at __delete() time check it, for instance.

- Arnaldo

> - free(machine);
> + WARN_ONCE((machine->allocated ? free(machine), 0 : -1),
> + "WARNING: deleting a non-allocated machine. Skip.\n");
> }
>
> Thank you.


\
 
 \ /
  Last update: 2015-12-16 21:01    [W:0.120 / U:0.896 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site