[retro-gtk] module-query: Use autocleanups



commit f3bd2ddc1d8fe5b76e12b4f19f561f634b81656e
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Sun Apr 11 17:11:14 2021 +0200

    module-query: Use autocleanups
    
    This makes the code safer and more concise.

 retro-gtk/retro-module-query.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
---
diff --git a/retro-gtk/retro-module-query.c b/retro-gtk/retro-module-query.c
index 28dd8a3..e71ecf9 100644
--- a/retro-gtk/retro-module-query.c
+++ b/retro-gtk/retro-module-query.c
@@ -45,25 +45,18 @@ retro_module_query_init (RetroModuleQuery *self)
 static gchar **
 get_plugin_lookup_paths (void)
 {
-  gchar **envp;
+  g_auto (GStrv) envp = NULL;
   const gchar *env_plugin_path;
-  gchar *full_plugin_path;
-  gchar **result;
+  g_autofree gchar *full_plugin_path = NULL;
 
   envp = g_get_environ ();
   env_plugin_path = g_environ_getenv (envp, RETRO_MODULE_QUERY_ENV_PLUGIN_PATH);
-  if (env_plugin_path == NULL) {
-    g_strfreev (envp);
-
+  if (env_plugin_path == NULL)
     return g_strsplit (RETRO_PLUGIN_PATH, ":", 0);
-  }
 
   full_plugin_path = g_strconcat (env_plugin_path, ":", RETRO_PLUGIN_PATH, NULL);
-  g_strfreev (envp);
-  result = g_strsplit (full_plugin_path, ":", 0);
-  g_free (full_plugin_path);
 
-  return result;
+  return g_strsplit (full_plugin_path, ":", 0);
 }
 
 /* Public */
@@ -79,17 +72,14 @@ get_plugin_lookup_paths (void)
 RetroModuleIterator *
 retro_module_query_iterator (RetroModuleQuery *self)
 {
-  RetroModuleIterator *result;
-  gchar **paths;
+  g_auto (GStrv) paths = NULL;
 
   g_return_val_if_fail (RETRO_IS_MODULE_QUERY (self), NULL);
 
   paths = get_plugin_lookup_paths ();
-  result = retro_module_iterator_new ((const gchar * const *) paths,
-                                      self->recursive);
-  g_strfreev (paths);
 
-  return result;
+  return retro_module_iterator_new ((const gchar * const *) paths,
+                                    self->recursive);
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]