[retro-gtk/module-cleanup: 2/6] module: Use g_autoptr and fix a few leaks
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk/module-cleanup: 2/6] module: Use g_autoptr and fix a few leaks
- Date: Sat, 23 May 2020 09:24:40 +0000 (UTC)
commit c2e3b57655739358ec04fd21724dde089c5a9f61
Author: Adrien Plazas <kekun plazas laposte net>
Date: Sat May 23 10:35:24 2020 +0200
module: Use g_autoptr and fix a few leaks
file and absolute_path_file were leaked in retro_module_new().
retro-runner/retro-module.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
---
diff --git a/retro-runner/retro-module.c b/retro-runner/retro-module.c
index 4b2c83e..67caf05 100644
--- a/retro-runner/retro-module.c
+++ b/retro-runner/retro-module.c
@@ -47,6 +47,15 @@ G_DEFINE_TYPE (RetroModule, retro_module, G_TYPE_OBJECT)
/* Private */
+static gchar *
+get_absolute_path (const gchar *file_name)
+{
+ g_autoptr (GFile) file = g_file_new_for_path (file_name);
+ g_autoptr (GFile) absolute_path_file = g_file_resolve_relative_path (file, "");
+
+ return g_file_get_path (absolute_path_file);
+}
+
static void
try_delete_file (GFile *file)
{
@@ -116,9 +125,6 @@ RetroModule *
retro_module_new (const gchar *file_name)
{
RetroModule *self = NULL;
- GFile *file;
- GFileIOStream *ios = NULL;
- GFile *absolute_path_file;
gpointer function;
GError *inner_error = NULL;
@@ -126,13 +132,13 @@ retro_module_new (const gchar *file_name)
self = (RetroModule*) g_object_new (RETRO_TYPE_MODULE, NULL);
- file = g_file_new_for_path (file_name);
- absolute_path_file = g_file_resolve_relative_path (file, "");
- self->file_name = g_file_get_path (absolute_path_file);
+ self->file_name = get_absolute_path (file_name);
self->is_a_copy = FALSE;
if (g_hash_table_contains (retro_module_loaded_modules, self->file_name)) {
- file = g_file_new_for_path (self->file_name);
+ g_autoptr (GFile) file = g_file_new_for_path (self->file_name);
+ g_autoptr (GFileIOStream) ios = NULL;
+
self->tmp_file = g_file_new_tmp (NULL, &ios, &inner_error);
if (G_UNLIKELY (inner_error != NULL)) {
g_debug ("%s", inner_error->message);
@@ -161,11 +167,6 @@ retro_module_new (const gchar *file_name)
}
self->is_a_copy = TRUE;
load_module (self, self->file_name);
-
- if (ios != NULL)
- g_object_unref (ios);
- if (file != NULL)
- g_object_unref (file);
}
else {
g_hash_table_add (retro_module_loaded_modules, g_strdup (self->file_name));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]