summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Bzatek <[email protected]>2020-07-22 17:44:56 +0200
committerLuke from DC <[email protected]>2020-07-29 20:47:20 +0000
commitc4bede86f6196d02f356eff49d3edb1a68f9b9b0 (patch)
treed654bf754f04311c91b0d0030e261394f290f84e
parent9768370328828ab8cc32f828fac3f34661bcca9c (diff)
downloadmate-panel-c4bede86f6196d02f356eff49d3edb1a68f9b9b0.tar.bz2
mate-panel-c4bede86f6196d02f356eff49d3edb1a68f9b9b0.tar.xz
panel-run-dialog: Fix leaking tree model strings
The gtk_tree_model_get() duplicates memory or adds a reference and any data need to be freed explicitly.
-rw-r--r--mate-panel/panel-run-dialog.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/mate-panel/panel-run-dialog.c b/mate-panel/panel-run-dialog.c
index f6fa95b8..fcd482ee 100644
--- a/mate-panel/panel-run-dialog.c
+++ b/mate-panel/panel-run-dialog.c
@@ -172,8 +172,8 @@ _panel_run_save_recent_programs_list (PanelRunDialog *dialog,
model = gtk_combo_box_get_model (GTK_COMBO_BOX (entry));
/* reasonable upper bound for zero-terminated array with new command */
- gchar const *items[gtk_tree_model_iter_n_children (model, NULL) + 2];
- guint items_added = 0;
+ gchar *items[gtk_tree_model_iter_n_children (model, NULL) + 2];
+ guint items_added = 0;
items[0] = lastcommand;
@@ -181,8 +181,10 @@ _panel_run_save_recent_programs_list (PanelRunDialog *dialog,
char *command;
do {
gtk_tree_model_get (model, &iter, 0, &command, -1);
- if (g_strcmp0 (command, lastcommand) == 0)
+ if (g_strcmp0 (command, lastcommand) == 0) {
+ g_free (command);
continue;
+ }
items[items_added + 1] = command;
items_added++;
} while (gtk_tree_model_iter_next (model, &iter));
@@ -192,13 +194,23 @@ _panel_run_save_recent_programs_list (PanelRunDialog *dialog,
guint pos;
for (pos = 0; pos < items_added / 2; pos++)
{
- gchar const * tmp = items[pos + 1];
+ gchar *tmp = items[pos + 1];
items[pos + 1] = items[items_added - pos];
items[items_added - pos] = tmp;
}
}
- items[history_max_size < items_added + 1 ? history_max_size : items_added + 1] = NULL;
- g_settings_set_strv (dialog->settings, PANEL_RUN_HISTORY_KEY, items);
+
+ if (history_max_size < items_added + 1) {
+ g_free (items[history_max_size]);
+ items[history_max_size] = NULL;
+ } else {
+ items[items_added + 1] = NULL;
+ }
+ g_settings_set_strv (dialog->settings, PANEL_RUN_HISTORY_KEY, (const gchar **)items);
+
+ /* free the items */
+ for (; items_added; items_added--)
+ g_free (items[items_added]);
}
}