GDesktopAppInfo: fix leaks
[platform/upstream/glib.git] / gio / gdesktopappinfo.c
index 025b70c..1bac191 100644 (file)
@@ -26,7 +26,6 @@
 #include <errno.h>
 #include <string.h>
 #include <unistd.h>
-#include <sys/wait.h>
 
 #ifdef HAVE_CRT_EXTERNS_H
 #include <crt_externs.h>
@@ -1374,12 +1373,12 @@ _g_desktop_app_info_launch_uris_internal (GAppInfo                   *appinfo,
        * the connection if we were the initial owner.
        */
       g_dbus_connection_flush (session_bus, NULL, NULL, NULL);
-      g_object_unref (session_bus);
     }
 
   completed = TRUE;
 
  out:
+  g_clear_object (&session_bus);
   g_strfreev (argv);
   g_strfreev (envp);
 
@@ -1850,8 +1849,7 @@ update_program_done (GPid     pid,
                     gpointer data)
 {
   /* Did the application exit correctly */
-  if (WIFEXITED (status) &&
-      WEXITSTATUS (status) == 0)
+  if (g_spawn_check_exit_status (status, NULL))
     {
       /* Here we could clean out any caches in use */
     }
@@ -2080,6 +2078,7 @@ g_desktop_app_info_ensure_saved (GDesktopAppInfo  *info,
   close (fd);
   
   res = g_file_set_contents (filename, data, data_size, error);
+  g_free (data);
   if (!res)
     {
       g_free (desktop_id);
@@ -3239,6 +3238,7 @@ get_all_desktop_entries_for_mime_type (const char  *base_mime_type,
   char **mime_types;
   char **default_entries;
   char **removed_associations;
+  gboolean already_found_handler;
   int i, j, k;
   GPtrArray *array;
   char **anc;
@@ -3290,6 +3290,11 @@ get_all_desktop_entries_for_mime_type (const char  *base_mime_type,
     {
       mime_type = mime_types[i];
 
+      /* This is true if we already found a handler for a more specific
+         mimetype. If its set we ignore any defaults for the less specific
+         mimetypes. */
+      already_found_handler = (desktop_entries != NULL);
+
       /* Go through all apps listed in user and system dirs */
       for (dir_list = mime_info_cache->dirs;
           dir_list != NULL;
@@ -3300,7 +3305,7 @@ get_all_desktop_entries_for_mime_type (const char  *base_mime_type,
           /* Pick the explicit default application if we got no result earlier
            * (ie, for more specific mime types)
            */
-          if (desktop_entries == NULL)
+          if (!already_found_handler)
             {
               entry = g_hash_table_lookup (dir->mimeapps_list_defaults_map, mime_type);
 
@@ -3326,7 +3331,7 @@ get_all_desktop_entries_for_mime_type (const char  *base_mime_type,
          default_entries = g_hash_table_lookup (dir->defaults_list_map, mime_type);
          for (j = 0; default_entries != NULL && default_entries[j] != NULL; j++)
             {
-              if (default_entry == NULL && old_default_entry == NULL && desktop_entries == NULL)
+              if (default_entry == NULL && old_default_entry == NULL && !already_found_handler)
                 old_default_entry = g_strdup (default_entries[j]);
 
               desktop_entries = append_desktop_entry (desktop_entries, default_entries[j], removed_entries);