summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Bzatek <[email protected]>2020-07-22 17:44:56 +0200
committerPablo Barciela <[email protected]>2020-08-03 13:46:34 +0200
commit63ef9f71bd1cafa627f55b5705114dce03b0a865 (patch)
tree97a181324803a1248153cc3a5ea9552cd3b59069
parent0119f31e89fea9a5d701a732685fe09f61500eb8 (diff)
downloadmate-panel-63ef9f71bd1cafa627f55b5705114dce03b0a865.tar.bz2
mate-panel-63ef9f71bd1cafa627f55b5705114dce03b0a865.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 e632acd6..51b70977 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]);
}
}