Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 23aaa3c1 authored by Steven Rostedt (Red Hat)'s avatar Steven Rostedt (Red Hat) Committed by Steven Rostedt
Browse files

tracing: Fix leak of ring buffer data when new instances creation fails

Yoshihiro Yunomae reported that the ring buffer data for a trace
instance does not get properly cleaned up when it fails. He proposed
a patch that manually cleaned the data up and addad a bunch of labels.
The labels are not needed because all trace array is allocated with
a kzalloc which initializes it to 0 and all kfree()s can take a NULL
pointer and will ignore it.

Adding a new helper function free_trace_buffers() that can also take
null buffers to free the buffers that were allocated by
allocate_trace_buffers().

Link: http://lkml.kernel.org/r/20140605223522.32311.31664.stgit@yunodevel



Reported-by: default avatarYoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent 748ec3a2
Loading
Loading
Loading
Loading
+20 −2
Original line number Original line Diff line number Diff line
@@ -6232,6 +6232,25 @@ static int allocate_trace_buffers(struct trace_array *tr, int size)
	return 0;
	return 0;
}
}


static void free_trace_buffers(struct trace_array *tr)
{
	if (!tr)
		return;

	if (tr->trace_buffer.buffer) {
		ring_buffer_free(tr->trace_buffer.buffer);
		tr->trace_buffer.buffer = NULL;
		free_percpu(tr->trace_buffer.data);
	}

#ifdef CONFIG_TRACER_MAX_TRACE
	if (tr->max_buffer.buffer) {
		ring_buffer_free(tr->max_buffer.buffer);
		tr->max_buffer.buffer = NULL;
	}
#endif
}

static int new_instance_create(const char *name)
static int new_instance_create(const char *name)
{
{
	struct trace_array *tr;
	struct trace_array *tr;
@@ -6290,8 +6309,7 @@ static int new_instance_create(const char *name)
	return 0;
	return 0;


 out_free_tr:
 out_free_tr:
	if (tr->trace_buffer.buffer)
	free_trace_buffers(tr);
		ring_buffer_free(tr->trace_buffer.buffer);
	free_cpumask_var(tr->tracing_cpumask);
	free_cpumask_var(tr->tracing_cpumask);
	kfree(tr->name);
	kfree(tr->name);
	kfree(tr);
	kfree(tr);