[glib/wip/baedert/xdgmime-leak: 1/2] xdgmime: Free global data when rereading



commit aebdbd4acad0fa181d56202ee5e92478e476e5fd
Author: Timm Bäder <mail baedert org>
Date:   Sun Jul 21 11:29:32 2019 +0200

    xdgmime: Free global data when rereading
    
    We were leading all of them in the need_reread case.

 gio/xdgmime/xdgmime.c | 76 ++++++++++++++++++++++++++++-----------------------
 1 file changed, 42 insertions(+), 34 deletions(-)
---
diff --git a/gio/xdgmime/xdgmime.c b/gio/xdgmime/xdgmime.c
index 9bb93f791..fa45d7a0c 100644
--- a/gio/xdgmime/xdgmime.c
+++ b/gio/xdgmime/xdgmime.c
@@ -496,6 +496,45 @@ xdg_check_time_and_dirs (void)
   return retval;
 }
 
+static void
+free_globals (void)
+{
+  if (global_hash)
+    {
+      _xdg_glob_hash_free (global_hash);
+      global_hash = NULL;
+    }
+  if (global_magic)
+    {
+      _xdg_mime_magic_free (global_magic);
+      global_magic = NULL;
+    }
+
+  if (alias_list)
+    {
+      _xdg_mime_alias_list_free (alias_list);
+      alias_list = NULL;
+    }
+
+  if (parent_list)
+    {
+      _xdg_mime_parent_list_free (parent_list);
+      parent_list = NULL;
+    }
+
+  if (icon_list)
+    {
+      _xdg_mime_icon_list_free (icon_list);
+      icon_list = NULL;
+    }
+
+  if (generic_icon_list)
+    {
+      _xdg_mime_icon_list_free (generic_icon_list);
+      generic_icon_list = NULL;
+    }
+}
+
 /* Called in every public function.  It reloads the hash function if need be.
  */
 static void
@@ -508,6 +547,8 @@ xdg_mime_init (void)
 
   if (need_reread)
     {
+      free_globals ();
+
       global_hash = _xdg_glob_hash_new ();
       global_magic = _xdg_mime_magic_new ();
       alias_list = _xdg_mime_alias_list_new ();
@@ -684,42 +725,9 @@ xdg_mime_shutdown (void)
       xdg_dir_time_list_free (dir_time_list);
       dir_time_list = NULL;
     }
-       
-  if (global_hash)
-    {
-      _xdg_glob_hash_free (global_hash);
-      global_hash = NULL;
-    }
-  if (global_magic)
-    {
-      _xdg_mime_magic_free (global_magic);
-      global_magic = NULL;
-    }
-
-  if (alias_list)
-    {
-      _xdg_mime_alias_list_free (alias_list);
-      alias_list = NULL;
-    }
 
-  if (parent_list)
-    {
-      _xdg_mime_parent_list_free (parent_list);
-      parent_list = NULL;
-    }
-
-  if (icon_list)
-    {
-      _xdg_mime_icon_list_free (icon_list);
-      icon_list = NULL;
-    }
+  free_globals ();
 
-  if (generic_icon_list)
-    {
-      _xdg_mime_icon_list_free (generic_icon_list);
-      generic_icon_list = NULL;
-    }
-  
   if (_caches)
     {
       int i;


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