Skip to content

Commit

Permalink
tracing/filters: Defer pred allocation, fix memory leak
Browse files Browse the repository at this point in the history
The predicates of an event and their filter structure are allocated
when we create an event filter for the first time.

These objects must be created once but each time we come with a new
filter, we overwrite such pre-existing allocation, if any.

Thus, this patch checks if the filter has already been allocated
before going ahead.

Spotted-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
LKML-Reference: <4A9CB1BA.3060402@cn.fujitsu.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
  • Loading branch information
Li Zefan authored and Frederic Weisbecker committed Sep 4, 2009
1 parent 8e254c1 commit c58b432
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions kernel/trace/trace_events_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ static int init_preds(struct ftrace_event_call *call)
struct filter_pred *pred;
int i;

if (call->filter)
return 0;

filter = call->filter = kzalloc(sizeof(*filter), GFP_KERNEL);
if (!call->filter)
return -ENOMEM;
Expand Down Expand Up @@ -447,11 +450,9 @@ static int init_subsystem_preds(struct event_subsystem *system)
if (strcmp(call->system, system->name) != 0)
continue;

if (!call->filter) {
err = init_preds(call);
if (err)
return err;
}
err = init_preds(call);
if (err)
return err;
}

return 0;
Expand Down

0 comments on commit c58b432

Please sign in to comment.