I have been running Valgrind on an application I have written which uses
gtksourceview and have found a few memory leaks.
My setup is:
Linux Mint 19.1 Tessa (up to date) with:
libgtksourceview-3.0-1 version: 3.24.7-1
libgtk-3-0 version: 3.22.30-1ubuntu1
libglib2.0-0 version: 2.56.3-0ubuntu0.18.04.1
Below is a cut & paste of the personal use patch I created
for version 3.24.7-1 of GtkSourceView.
I have tested the changes and they seem to be fine under my
system configuration, and valgrind no longer reports any leaks
regarding these. I have only tested the changes with my program
and setup so have no idea how they may affect other things.
Looking thru the source code on gitlab I see the bug in
gtksourcecompletion.c::init_tree_view has already been fixed so
it can be ignored below.
I have added comments below starting with ### to indicate the
relevant functions
I hope the info here helps!
diff -Naur /tmp/GtkSourceView3/gtksourceview3-3.24.7/gtksourceview/gtksourcebuffer.c /media/Data/Temp/Source/gtksourceview3-3.24.7/gtksourceview/gtksourcebuffer.c
--- /tmp/GtkSourceView3/gtksourceview3-3.24.7/gtksourceview/gtksourcebuffer.c 2017-05-17 08:50:16.000000000 -0700
+++ /media/Data/Temp/Source/gtksourceview3-3.24.7/gtksourceview/gtksourcebuffer.c 2019-02-17 09:53:22.287997103 -0800
@@ -2053,6 +2053,7 @@
### fcn 'gtk_source_buffer_create_source_mark'
GTK_TEXT_MARK (mark),
where);
+ g_object_unref (mark); // BUGFIX: mark was never unrefd -> leaked memory!
return mark;
}
diff -Naur /tmp/GtkSourceView3/gtksourceview3-3.24.7/gtksourceview/gtksourcecompletion.c /media/Data/Temp/Source/gtksourceview3-3.24.7/gtksourceview/gtksourcecompletion.c
--- /tmp/GtkSourceView3/gtksourceview3-3.24.7/gtksourceview/gtksourcecompletion.c 2017-05-17 08:50:16.000000000 -0700
+++ /media/Data/Temp/Source/gtksourceview3-3.24.7/gtksourceview/gtksourcecompletion.c 2019-02-17 09:56:27.144276483 -0800
@@ -2028,7 +2028,7 @@
### fcn 'init_tree_view' ALREADY FIXED!!
GtkTreeViewColumn *column;
GtkCellRenderer *cell_renderer;
GtkStyleContext *style_context;
- GdkRGBA background_color;
+ GdkRGBA *background_color = NULL; // BUGFIX:
GdkRGBA foreground_color;
completion->priv->tree_view_proposals = GTK_TREE_VIEW (gtk_builder_get_object (builder, "tree_view_proposals"));
@@ -2094,7 +2094,7 @@
gtk_style_context_restore (style_context);
g_object_set (cell_renderer,
- "cell-background-rgba", &background_color,
+ "cell-background-rgba", background_color, // BUGFIX:
NULL);
g_object_bind_property (completion, "show-icons",
@@ -2116,7 +2116,7 @@
g_object_set (cell_renderer,
"foreground-rgba", &foreground_color,
- "cell-background-rgba", &background_color,
+ "cell-background-rgba", background_color, // BUGFIX:
NULL);
/* Accelerators cell renderer */
@@ -2132,7 +2132,7 @@
g_object_set (cell_renderer,
"foreground-rgba", &foreground_color,
- "cell-background-rgba", &background_color,
+ "cell-background-rgba", background_color, // BUGFIX:
NULL);
gtk_tree_view_column_set_cell_data_func (column,
@@ -2146,6 +2146,8 @@
G_CALLBACK (accelerators_notify_cb),
column,
0);
+
+ gdk_rgba_free (background_color); // BUGFIX:
}
static void
@@ -2951,7 +2953,8 @@
### fcn 'gtk_source_completion_remove_provider'
return FALSE;
}
- completion->priv->providers = g_list_remove_link (completion->priv->providers, item);
+ // BUGFIX: was g_list_remove_link -> leaked memory!
+ completion->priv->providers = g_list_delete_link (completion->priv->providers, item);
g_object_unref (provider);
diff -Naur /tmp/GtkSourceView3/gtksourceview3-3.24.7/gtksourceview/gtksourcegutterrenderermarks.c /media/Data/Temp/Source/gtksourceview3-3.24.7/gtksourceview/gtksourcegutterrenderermarks.c
--- /tmp/GtkSourceView3/gtksourceview3-3.24.7/gtksourceview/gtksourcegutterrenderermarks.c 2017-05-17 08:50:16.000000000 -0700
+++ /media/Data/Temp/Source/gtksourceview3-3.24.7/gtksourceview/gtksourcegutterrenderermarks.c 2019-02-17 09:56:45.431909217 -0800
@@ -200,6 +200,10 @@
### 'fcn gutter_renderer_query_data'
"xalign", 0.5,
"alignment-mode", GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST,
NULL);
+
+ // BUGFIX: pixbuf was never unrefd -> leaked memory!
+ if (pixbuf != NULL)
+ g_object_unref (pixbuf);
}
static gboolean
@@ -345,13 +349,17 @@
### 'fcn gutter_renderer_query_tooltip'
if (marks != NULL)
{
+ gboolean ret; // BUGFIX:
marks = g_slist_sort_with_data (marks,
sort_marks_by_priority,
view);
marks = g_slist_reverse (marks);
- return set_tooltip_widget_from_marks (view, tooltip, marks);
+ // BUGFIX: GSList was not freed -> leaked memory!
+ ret = set_tooltip_widget_from_marks (view, tooltip, marks);
+ g_slist_free (marks);
+ return ret;
}
return FALSE;