summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrbuj <[email protected]>2022-01-30 11:59:09 +0100
committerraveit65 <[email protected]>2023-04-15 22:34:50 +0200
commit9c8ab8787724da4603c023adf406d0d4909bb8de (patch)
tree0543b809b30eda3c83ae3362d0228bbbce87c41e
parent457669530e7f68a8b777ea2aaa61d79cf3c2a673 (diff)
downloadengrampa-9c8ab8787724da4603c023adf406d0d4909bb8de.tar.bz2
engrampa-9c8ab8787724da4603c023adf406d0d4909bb8de.tar.xz
fr-process: fix memory leak
-rw-r--r--src/fr-process.c35
1 files changed, 9 insertions, 26 deletions
diff --git a/src/fr-process.c b/src/fr-process.c
index c961485..56a1ddb 100644
--- a/src/fr-process.c
+++ b/src/fr-process.c
@@ -85,22 +85,16 @@ fr_command_info_new (void)
}
static void
-fr_command_info_free (FrCommandInfo *info)
+fr_command_info_free (gpointer data)
{
+ FrCommandInfo *info = data;
+
if (info == NULL)
return;
- if (info->args != NULL) {
- g_list_free_full (info->args, g_free);
- info->args = NULL;
- }
-
- if (info->dir != NULL) {
- g_free (info->dir);
- info->dir = NULL;
- }
-
- g_free (info);
+ g_list_free_full (info->args, g_free);
+ g_free (info->dir);
+ g_clear_pointer (&info, g_free);
}
static void
@@ -289,7 +283,7 @@ fr_process_init (FrProcess *process)
process->term_on_stop = TRUE;
- process->priv->comm = g_ptr_array_new ();
+ process->priv->comm = g_ptr_array_new_with_free_func (fr_command_info_free);
process->priv->n_comm = -1;
process->priv->current_comm = -1;
@@ -330,9 +324,8 @@ fr_process_finalize (GObject *object)
process = FR_PROCESS (object);
fr_process_stop_priv (process, FALSE);
- fr_process_clear (process);
- g_ptr_array_free (process->priv->comm, FALSE);
+ g_ptr_array_free (process->priv->comm, TRUE);
fr_channel_data_free (&process->out);
fr_channel_data_free (&process->err);
@@ -378,9 +371,7 @@ fr_process_begin_command_at (FrProcess *process,
process->priv->current_comm = index;
old_c_info = g_ptr_array_index (process->priv->comm, index);
-
- if (old_c_info != NULL)
- fr_command_info_free (old_c_info);
+ fr_command_info_free (old_c_info);
info = fr_command_info_new ();
info->args = g_list_prepend (NULL, g_strdup (arg));
@@ -561,14 +552,6 @@ fr_process_clear (FrProcess *process)
g_return_if_fail (process != NULL);
- for (i = 0; i <= process->priv->n_comm; i++) {
- FrCommandInfo *info;
-
- info = g_ptr_array_index (process->priv->comm, i);
- fr_command_info_free (info);
- g_ptr_array_index (process->priv->comm, i) = NULL;
- }
-
for (i = 0; i <= process->priv->n_comm; i++)
g_ptr_array_remove_index_fast (process->priv->comm, 0);