From 702493053063688e6341fc1cfc3f9450c120b4ba Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 30 Jan 2013 11:50:26 +1100 Subject: Properly destroy the cairo context when we're done with it Henrik reports that on OSX, not destroying the cairo context results in a corrupted profile display. It seems to just leak memory on Linux. For gtk3, the cairo context is embedded in the GtkDrawable, for gtk2 we need to create and destroy it appropriately. Although maybe we could just make it static instead of creating/destroying it all the time. Anyway, this goes back to the old cairo destroy logic for gtk2. Reported-and-analyzed-by: Henrik Brautaset Aronsen Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- gtk-gui.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/gtk-gui.c b/gtk-gui.c index 2df816675..8cb5c47e3 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -1692,7 +1692,7 @@ static gboolean profile_tooltip (GtkWidget *widget, gint x, gint y, static double zoom_factor = 1.0; static int zoom_x = -1, zoom_y = -1; -static gboolean common_drawing_function(GtkWidget *widget, struct graphics_context *gc) +static void common_drawing_function(GtkWidget *widget, struct graphics_context *gc) { int i = 0; struct dive *dive = current_dive; @@ -1724,8 +1724,6 @@ static gboolean common_drawing_function(GtkWidget *widget, struct graphics_conte tooltips = 0; plot(gc, dive, SC_SCREEN); } - - return FALSE; } #if GTK_CHECK_VERSION(3,0,0) @@ -1742,7 +1740,8 @@ static gboolean draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data) gc.drawing_area.height = height; gc.cr = cr; - return common_drawing_function(widget, &gc); + common_drawing_function(widget, &gc); + return FALSE; } #else /* gtk2 */ @@ -1759,7 +1758,9 @@ static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer gc.drawing_area.height = allocation.height; gc.cr = gdk_cairo_create(gtk_widget_get_window(widget)); - return common_drawing_function(widget, &gc); + common_drawing_function(widget, &gc); + cairo_destroy(gc.cr); + return FALSE; } #endif -- cgit v1.2.3-70-g09d2