[PATCH][kernelshark] trace-graph: Fix trace_seq free-before-use

From: Stefan Hajnoczi
Date: Sun Sep 05 2010 - 07:05:51 EST


Commit e892161f731e958980fa977e2d7980f3cf0819ce changed trace_seq to
dynamically expand its buffer. In two instances the destroy function
was called too early, causing a freed s.buffer to be used.

Signed-off-by: Stefan Hajnoczi <stefanha@xxxxxxxxxxxxxxxxxx>
---
trace-graph.c | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/trace-graph.c b/trace-graph.c
index 44c1273..4e91fe8 100644
--- a/trace-graph.c
+++ b/trace-graph.c
@@ -1666,14 +1666,17 @@ static gint draw_event_label(struct graph_info *ginfo, gint i,
*/
ret = trace_graph_plot_display_last_event(ginfo, plot, &s,
convert_x_to_time(ginfo, p2-1));
- trace_seq_destroy(&s);
- if (!ret)
+ if (!ret) {
+ trace_seq_destroy(&s);
return p2;
+ }

layout = gtk_widget_create_pango_layout(ginfo->draw, s.buffer);
pango_layout_set_font_description(layout, font);
pango_layout_get_pixel_size(layout, &text_width, &text_height);

+ trace_seq_destroy(&s);
+
/* Lets see if we can print this info */
if (p2 < text_width)
start = 1;
@@ -1967,7 +1970,6 @@ static void draw_timeline(struct graph_info *ginfo, gint width)
convert_nano(time, &sec, &usec);
trace_seq_init(&s);
trace_seq_printf(&s, "%lu.%06lu", sec, usec);
- trace_seq_destroy(&s);

gdk_draw_line(ginfo->curr_pixmap, ginfo->draw->style->black_gc,
mid, height, mid, height + 5);
@@ -1978,6 +1980,7 @@ static void draw_timeline(struct graph_info *ginfo, gint width)
gdk_draw_layout(ginfo->curr_pixmap, ginfo->draw->style->black_gc,
mid - (w / 2), height+10, layout);
g_object_unref(layout);
+ trace_seq_destroy(&s);
}
}

--
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/