Commit 91862cc7 authored by Wenwen Wang's avatar Wenwen Wang Committed by Steven Rostedt (VMware)

tracing: Fix a memory leak by early error exit in trace_pid_write()

In trace_pid_write(), the buffer for trace parser is allocated through
kmalloc() in trace_parser_get_init(). Later on, after the buffer is used,
it is then freed through kfree() in trace_parser_put(). However, it is
possible that trace_pid_write() is terminated due to unexpected errors,
e.g., ENOMEM. In that case, the allocated buffer will not be freed, which
is a memory leak bug.

To fix this issue, free the allocated buffer when an error is encountered.

Link: http://lkml.kernel.org/r/1555726979-15633-1-git-send-email-wang6495@umn.edu

Fixes: f4d34a87 ("tracing: Use pid bitmap instead of a pid array for set_event_pid")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarWenwen Wang <wang6495@umn.edu>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent b9872226
...@@ -496,8 +496,10 @@ int trace_pid_write(struct trace_pid_list *filtered_pids, ...@@ -496,8 +496,10 @@ int trace_pid_write(struct trace_pid_list *filtered_pids,
* not modified. * not modified.
*/ */
pid_list = kmalloc(sizeof(*pid_list), GFP_KERNEL); pid_list = kmalloc(sizeof(*pid_list), GFP_KERNEL);
if (!pid_list) if (!pid_list) {
trace_parser_put(&parser);
return -ENOMEM; return -ENOMEM;
}
pid_list->pid_max = READ_ONCE(pid_max); pid_list->pid_max = READ_ONCE(pid_max);
...@@ -507,6 +509,7 @@ int trace_pid_write(struct trace_pid_list *filtered_pids, ...@@ -507,6 +509,7 @@ int trace_pid_write(struct trace_pid_list *filtered_pids,
pid_list->pids = vzalloc((pid_list->pid_max + 7) >> 3); pid_list->pids = vzalloc((pid_list->pid_max + 7) >> 3);
if (!pid_list->pids) { if (!pid_list->pids) {
trace_parser_put(&parser);
kfree(pid_list); kfree(pid_list);
return -ENOMEM; return -ENOMEM;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment