Fix more memory leaks

Found by Valgrind when starting xfce4-taskmanager.
This commit is contained in:
Gaël Bonithon
2023-09-10 12:01:40 +02:00
parent bfe5308f05
commit 4209c4ac41
3 changed files with 25 additions and 3 deletions

View File

@@ -225,8 +225,11 @@ int main (int argc, char *argv[])
if (!g_option_context_parse (opt_context, &argc, &argv, &error))
{
g_print ("Unable to parse arguments: %s\n", error->message);
g_error_free (error);
g_option_context_free (opt_context);
return 1;
}
g_option_context_free (opt_context);
app = g_application_new ("xfce.taskmanager", 0);
g_application_register (G_APPLICATION (app), NULL, &error);

View File

@@ -91,6 +91,19 @@ xtm_cross_link_new (void)
static void
xtm_cross_link_free (gpointer data)
{
XtmCrossLink *lnk = data;
if (lnk != NULL && lnk->path != NULL)
gtk_tree_path_free (lnk->path);
g_free (lnk);
}
static void
xtm_process_tree_model_class_init (XtmProcessTreeModelClass *klass)
{
@@ -132,7 +145,7 @@ xtm_process_tree_model_iface_init (GtkTreeModelIface *iface)
static void
xtm_process_tree_model_init (XtmProcessTreeModel *treemodel)
{
treemodel->list = g_sequence_new (g_free);
treemodel->list = g_sequence_new (xtm_cross_link_free);
treemodel->tree = g_node_new (NULL);
treemodel->c_column = XTM_PTV_COLUMN_PID;
@@ -883,7 +896,7 @@ xtm_process_tree_model_rows_reordered (XtmProcessTreeModel *treemodel, GtkTreePa
not_persist = ! (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_ITERS_PERSIST);
/* New list to hold the new order */
s_list = g_sequence_new (g_free);
s_list = g_sequence_new (xtm_cross_link_free);
s_iter = g_sequence_get_end_iter (s_list);
for (i = 0; i < size; i++)

View File

@@ -259,7 +259,9 @@ model_update_tree_iter (XtmTaskManager *manager, GtkTreeIter *iter, glong timest
-1);
#ifdef HAVE_WNCK
if (app != NULL && icon == NULL)
if (icon != NULL)
g_object_unref (icon);
else if (app != NULL)
gtk_list_store_set (GTK_LIST_STORE (model), iter, XTM_PTV_COLUMN_ICON, app->icon, -1);
if (app != NULL && full_cmdline == FALSE)
@@ -281,6 +283,8 @@ model_update_tree_iter (XtmTaskManager *manager, GtkTreeIter *iter, glong timest
if (g_strcmp0 (task->state, old_state) != 0 && background == NULL)
{
/* Set yellow color for changing state */
g_free (background);
g_free (foreground);
background = g_strdup ("#fff176");
foreground = g_strdup ("#000000");
old_timestamp = timestamp - TIMESTAMP_DELTA + 3;
@@ -295,6 +299,8 @@ model_update_tree_iter (XtmTaskManager *manager, GtkTreeIter *iter, glong timest
else
{
/* Reset color */
g_free (background);
g_free (foreground);
background = NULL;
foreground = NULL;
}