* [PATCH][GIT PULL] tracing: fix memory leak in trace_stat
@ 2009-03-21 6:54 Steven Rostedt
2009-03-21 9:43 ` Ingo Molnar
0 siblings, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2009-03-21 6:54 UTC (permalink / raw)
To: LKML; +Cc: Ingo Molnar, Andrew Morton, Frédéric Weisbecker
Ingo,
Please pull the latest tip/tracing/ftrace tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tip/tracing/ftrace
Steven Rostedt (1):
tracing: fix memory leak in trace_stat
----
kernel/trace/trace_stat.c | 23 +++++++++++++----------
1 files changed, 13 insertions(+), 10 deletions(-)
---------------------------
commit 38c007b2f0b40747074508d8304f2cb01148fb05
Author: Steven Rostedt <srostedt@redhat.com>
Date: Sat Mar 21 02:44:50 2009 -0400
tracing: fix memory leak in trace_stat
If the function profiler does not have any items recorded and one were
to cat the function stat file, the kernel would take a BUG with a NULL
pointer dereference.
Looking further into this, I found that returning NULL from stat_start
did not stop the stat logic, and would later call stat_next. This breaks
from the way seq_file works, so I looked into fixing the stat code.
This is where I noticed that the last next_entry is never freed.
It is allocated, and if the stat_next returns NULL, the code breaks out
of the loop, unlocks the mutex and exits. We never link the next_entry
nor do we free it. Thus it is a real memory leak.
This patch rearranges the code a bit to not only fix the memory leak,
but also to act more like seq_file where nothing is printed if there
is nothing to print. That is, stat_start returns NULL.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
diff --git a/kernel/trace/trace_stat.c b/kernel/trace/trace_stat.c
index 39310e3..f71b85b 100644
--- a/kernel/trace/trace_stat.c
+++ b/kernel/trace/trace_stat.c
@@ -75,7 +75,7 @@ static int stat_seq_init(struct tracer_stat_session *session)
{
struct trace_stat_list *iter_entry, *new_entry;
struct tracer_stat *ts = session->ts;
- void *prev_stat;
+ void *stat;
int ret = 0;
int i;
@@ -85,6 +85,10 @@ static int stat_seq_init(struct tracer_stat_session *session)
if (!ts->stat_cmp)
ts->stat_cmp = dummy_cmp;
+ stat = ts->stat_start();
+ if (!stat)
+ goto exit;
+
/*
* The first entry. Actually this is the second, but the first
* one (the stat_list head) is pointless.
@@ -99,14 +103,19 @@ static int stat_seq_init(struct tracer_stat_session *session)
list_add(&new_entry->list, &session->stat_list);
- new_entry->stat = ts->stat_start();
- prev_stat = new_entry->stat;
+ new_entry->stat = stat;
/*
* Iterate over the tracer stat entries and store them in a sorted
* list.
*/
for (i = 1; ; i++) {
+ stat = ts->stat_next(stat, i);
+
+ /* End of insertion */
+ if (!stat)
+ break;
+
new_entry = kmalloc(sizeof(struct trace_stat_list), GFP_KERNEL);
if (!new_entry) {
ret = -ENOMEM;
@@ -114,11 +123,7 @@ static int stat_seq_init(struct tracer_stat_session *session)
}
INIT_LIST_HEAD(&new_entry->list);
- new_entry->stat = ts->stat_next(prev_stat, i);
-
- /* End of insertion */
- if (!new_entry->stat)
- break;
+ new_entry->stat = stat;
list_for_each_entry(iter_entry, &session->stat_list, list) {
@@ -137,8 +142,6 @@ static int stat_seq_init(struct tracer_stat_session *session)
break;
}
}
-
- prev_stat = new_entry->stat;
}
exit:
mutex_unlock(&session->stat_mutex);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH][GIT PULL] tracing: fix memory leak in trace_stat
2009-03-21 6:54 [PATCH][GIT PULL] tracing: fix memory leak in trace_stat Steven Rostedt
@ 2009-03-21 9:43 ` Ingo Molnar
2009-03-24 7:43 ` Lai Jiangshan
0 siblings, 1 reply; 5+ messages in thread
From: Ingo Molnar @ 2009-03-21 9:43 UTC (permalink / raw)
To: Steven Rostedt; +Cc: LKML, Andrew Morton, Frédéric Weisbecker
* Steven Rostedt <rostedt@goodmis.org> wrote:
> Ingo,
>
> Please pull the latest tip/tracing/ftrace tree, which can be found at:
>
> git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
> tip/tracing/ftrace
>
>
> Steven Rostedt (1):
> tracing: fix memory leak in trace_stat
>
> ----
> kernel/trace/trace_stat.c | 23 +++++++++++++----------
> 1 files changed, 13 insertions(+), 10 deletions(-)
Pulled, thanks Steve!
Ingo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH][GIT PULL] tracing: fix memory leak in trace_stat
2009-03-21 9:43 ` Ingo Molnar
@ 2009-03-24 7:43 ` Lai Jiangshan
2009-03-24 11:20 ` Ingo Molnar
0 siblings, 1 reply; 5+ messages in thread
From: Lai Jiangshan @ 2009-03-24 7:43 UTC (permalink / raw)
To: Ingo Molnar
Cc: Steven Rostedt, LKML, Andrew Morton,
Frédéric Weisbecker
Ingo Molnar wrote:
> * Steven Rostedt <rostedt@goodmis.org> wrote:
>
>> Ingo,
>>
>> Please pull the latest tip/tracing/ftrace tree, which can be found at:
>>
>> git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
>> tip/tracing/ftrace
>>
>>
>> Steven Rostedt (1):
>> tracing: fix memory leak in trace_stat
>>
>> ----
>> kernel/trace/trace_stat.c | 23 +++++++++++++----------
>> 1 files changed, 13 insertions(+), 10 deletions(-)
>
> Pulled, thanks Steve!
>
> Ingo
>
Hi, Ingo
I found this patch is not in the tip tree.
Thanks, Lai
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH][GIT PULL] tracing: fix memory leak in trace_stat
2009-03-24 7:43 ` Lai Jiangshan
@ 2009-03-24 11:20 ` Ingo Molnar
2009-03-24 13:11 ` Steven Rostedt
0 siblings, 1 reply; 5+ messages in thread
From: Ingo Molnar @ 2009-03-24 11:20 UTC (permalink / raw)
To: Lai Jiangshan
Cc: Steven Rostedt, LKML, Andrew Morton,
Frédéric Weisbecker
* Lai Jiangshan <laijs@cn.fujitsu.com> wrote:
> Ingo Molnar wrote:
> > * Steven Rostedt <rostedt@goodmis.org> wrote:
> >
> >> Ingo,
> >>
> >> Please pull the latest tip/tracing/ftrace tree, which can be found at:
> >>
> >> git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
> >> tip/tracing/ftrace
> >>
> >>
> >> Steven Rostedt (1):
> >> tracing: fix memory leak in trace_stat
> >>
> >> ----
> >> kernel/trace/trace_stat.c | 23 +++++++++++++----------
> >> 1 files changed, 13 insertions(+), 10 deletions(-)
> >
> > Pulled, thanks Steve!
> >
> > Ingo
> >
>
> Hi, Ingo
>
> I found this patch is not in the tip tree.
It was tied to the function profiler which is still being debated.
Steve, mind re-anchoring that commit?
Ingo
^ permalink raw reply [flat|nested] 5+ messages in thread
* (no subject)
2009-03-24 11:20 ` Ingo Molnar
@ 2009-03-24 13:11 ` Steven Rostedt
0 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2009-03-24 13:11 UTC (permalink / raw)
To: Ingo Molnar
Cc: Lai Jiangshan, LKML, Andrew Morton, Frédéric Weisbecker
On Tue, 24 Mar 2009, Ingo Molnar wrote:
>
> * Lai Jiangshan <laijs@cn.fujitsu.com> wrote:
> > >> Steven Rostedt (1):
> > >> tracing: fix memory leak in trace_stat
[...]
> >
> > Hi, Ingo
> >
> > I found this patch is not in the tip tree.
>
> It was tied to the function profiler which is still being debated.
> Steve, mind re-anchoring that commit?
Hi Ingo,
Just created a branch from your latest tracing/ftrace and cherry picked
this change. I'll rebase my tip/tracing/ftrace branch on your changes
as soon as I see it in. I have more changes for the function profiler that
I think will make it worth having. Soon to be announced.
Please pull the latest tip/tracing/ftrace-1 tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tip/tracing/ftrace-1
Steven Rostedt (1):
tracing: fix memory leak in trace_stat
----
kernel/trace/trace_stat.c | 23 +++++++++++++----------
1 files changed, 13 insertions(+), 10 deletions(-)
---------------------------
commit 098335215a4921a8a54193829eaed602dca24df5
Author: Steven Rostedt <srostedt@redhat.com>
Date: Sat Mar 21 02:44:50 2009 -0400
tracing: fix memory leak in trace_stat
If the function profiler does not have any items recorded and one were
to cat the function stat file, the kernel would take a BUG with a NULL
pointer dereference.
Looking further into this, I found that returning NULL from stat_start
did not stop the stat logic, and would later call stat_next. This breaks
from the way seq_file works, so I looked into fixing the stat code.
This is where I noticed that the last next_entry is never freed.
It is allocated, and if the stat_next returns NULL, the code breaks out
of the loop, unlocks the mutex and exits. We never link the next_entry
nor do we free it. Thus it is a real memory leak.
This patch rearranges the code a bit to not only fix the memory leak,
but also to act more like seq_file where nothing is printed if there
is nothing to print. That is, stat_start returns NULL.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
diff --git a/kernel/trace/trace_stat.c b/kernel/trace/trace_stat.c
index 39310e3..f71b85b 100644
--- a/kernel/trace/trace_stat.c
+++ b/kernel/trace/trace_stat.c
@@ -75,7 +75,7 @@ static int stat_seq_init(struct tracer_stat_session *session)
{
struct trace_stat_list *iter_entry, *new_entry;
struct tracer_stat *ts = session->ts;
- void *prev_stat;
+ void *stat;
int ret = 0;
int i;
@@ -85,6 +85,10 @@ static int stat_seq_init(struct tracer_stat_session *session)
if (!ts->stat_cmp)
ts->stat_cmp = dummy_cmp;
+ stat = ts->stat_start();
+ if (!stat)
+ goto exit;
+
/*
* The first entry. Actually this is the second, but the first
* one (the stat_list head) is pointless.
@@ -99,14 +103,19 @@ static int stat_seq_init(struct tracer_stat_session *session)
list_add(&new_entry->list, &session->stat_list);
- new_entry->stat = ts->stat_start();
- prev_stat = new_entry->stat;
+ new_entry->stat = stat;
/*
* Iterate over the tracer stat entries and store them in a sorted
* list.
*/
for (i = 1; ; i++) {
+ stat = ts->stat_next(stat, i);
+
+ /* End of insertion */
+ if (!stat)
+ break;
+
new_entry = kmalloc(sizeof(struct trace_stat_list), GFP_KERNEL);
if (!new_entry) {
ret = -ENOMEM;
@@ -114,11 +123,7 @@ static int stat_seq_init(struct tracer_stat_session *session)
}
INIT_LIST_HEAD(&new_entry->list);
- new_entry->stat = ts->stat_next(prev_stat, i);
-
- /* End of insertion */
- if (!new_entry->stat)
- break;
+ new_entry->stat = stat;
list_for_each_entry(iter_entry, &session->stat_list, list) {
@@ -137,8 +142,6 @@ static int stat_seq_init(struct tracer_stat_session *session)
break;
}
}
-
- prev_stat = new_entry->stat;
}
exit:
mutex_unlock(&session->stat_mutex);
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-03-24 13:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-21 6:54 [PATCH][GIT PULL] tracing: fix memory leak in trace_stat Steven Rostedt
2009-03-21 9:43 ` Ingo Molnar
2009-03-24 7:43 ` Lai Jiangshan
2009-03-24 11:20 ` Ingo Molnar
2009-03-24 13:11 ` Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox