tracing/events: fix memory leak when unloading module
When unloading a module, memory allocated by init_preds() and trace_define_field() is not freed. [ Impact: fix memory leak ] Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> Acked-by: Frederic Weisbecker <fweisbec@gmail.com> Acked-by: Steven Rostedt <rostedt@goodmis.org> Cc: Tom Zanussi <tzanussi@gmail.com> LKML-Reference: <4A00F6E0.3040503@cn.fujitsu.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
parent
96d17980fa
commit
2df75e4157
|
@ -116,6 +116,7 @@ struct ftrace_event_call {
|
||||||
#define MAX_FILTER_STR_VAL 128
|
#define MAX_FILTER_STR_VAL 128
|
||||||
|
|
||||||
extern int init_preds(struct ftrace_event_call *call);
|
extern int init_preds(struct ftrace_event_call *call);
|
||||||
|
extern void destroy_preds(struct ftrace_event_call *call);
|
||||||
extern int filter_match_preds(struct ftrace_event_call *call, void *rec);
|
extern int filter_match_preds(struct ftrace_event_call *call, void *rec);
|
||||||
extern int filter_current_check_discard(struct ftrace_event_call *call,
|
extern int filter_current_check_discard(struct ftrace_event_call *call,
|
||||||
void *rec,
|
void *rec,
|
||||||
|
|
|
@ -60,6 +60,22 @@ err:
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(trace_define_field);
|
EXPORT_SYMBOL_GPL(trace_define_field);
|
||||||
|
|
||||||
|
#ifdef CONFIG_MODULES
|
||||||
|
|
||||||
|
static void trace_destroy_fields(struct ftrace_event_call *call)
|
||||||
|
{
|
||||||
|
struct ftrace_event_field *field, *next;
|
||||||
|
|
||||||
|
list_for_each_entry_safe(field, next, &call->fields, link) {
|
||||||
|
list_del(&field->link);
|
||||||
|
kfree(field->type);
|
||||||
|
kfree(field->name);
|
||||||
|
kfree(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_MODULES */
|
||||||
|
|
||||||
static void ftrace_clear_events(void)
|
static void ftrace_clear_events(void)
|
||||||
{
|
{
|
||||||
struct ftrace_event_call *call;
|
struct ftrace_event_call *call;
|
||||||
|
@ -925,6 +941,8 @@ static void trace_module_remove_events(struct module *mod)
|
||||||
unregister_ftrace_event(call->event);
|
unregister_ftrace_event(call->event);
|
||||||
debugfs_remove_recursive(call->dir);
|
debugfs_remove_recursive(call->dir);
|
||||||
list_del(&call->list);
|
list_del(&call->list);
|
||||||
|
trace_destroy_fields(call);
|
||||||
|
destroy_preds(call);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -346,6 +346,20 @@ static void filter_disable_preds(struct ftrace_event_call *call)
|
||||||
filter->preds[i]->fn = filter_pred_none;
|
filter->preds[i]->fn = filter_pred_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void destroy_preds(struct ftrace_event_call *call)
|
||||||
|
{
|
||||||
|
struct event_filter *filter = call->filter;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < MAX_FILTER_PRED; i++) {
|
||||||
|
if (filter->preds[i])
|
||||||
|
filter_free_pred(filter->preds[i]);
|
||||||
|
}
|
||||||
|
kfree(filter->preds);
|
||||||
|
kfree(filter);
|
||||||
|
call->filter = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
int init_preds(struct ftrace_event_call *call)
|
int init_preds(struct ftrace_event_call *call)
|
||||||
{
|
{
|
||||||
struct event_filter *filter;
|
struct event_filter *filter;
|
||||||
|
@ -374,13 +388,7 @@ int init_preds(struct ftrace_event_call *call)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
oom:
|
oom:
|
||||||
for (i = 0; i < MAX_FILTER_PRED; i++) {
|
destroy_preds(call);
|
||||||
if (filter->preds[i])
|
|
||||||
filter_free_pred(filter->preds[i]);
|
|
||||||
}
|
|
||||||
kfree(filter->preds);
|
|
||||||
kfree(call->filter);
|
|
||||||
call->filter = NULL;
|
|
||||||
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue