[glib] gunixmounts: Ensure that libmount's context gets freed on early returns



commit ed75b1623d4a51b16dc52a2044681b6d93e694d0
Author: Mario Sanchez Prada <mario endlessm com>
Date:   Wed Jul 27 13:50:54 2016 -0600

    gunixmounts: Ensure that libmount's context gets freed on early returns
    
    Otherwise, it will be leaked in case the relevant table (mtab, fstab)
    could not be retrieved for some reason.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=769238

 gio/gunixmounts.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/gio/gunixmounts.c b/gio/gunixmounts.c
index d7e3511..f87ba5d 100644
--- a/gio/gunixmounts.c
+++ b/gio/gunixmounts.c
@@ -393,7 +393,7 @@ _g_get_unix_mounts (void)
   ctxt = mnt_new_context ();
   mnt_context_get_mtab (ctxt, &table);
   if (!table)
-    return NULL;
+    goto out;
 
   iter = mnt_new_iter (MNT_ITER_FORWARD);
   while (mnt_table_next_fs (table, iter, &fs) == 0)
@@ -425,8 +425,9 @@ _g_get_unix_mounts (void)
 
       return_list = g_list_prepend (return_list, mount_entry);
     }
-
   mnt_free_iter (iter);
+
+ out:
   mnt_free_context (ctxt);
 
   return g_list_reverse (return_list);
@@ -876,7 +877,7 @@ _g_get_unix_mount_points (void)
   ctxt = mnt_new_context ();
   mnt_context_get_fstab (ctxt, &table);
   if (!table)
-    return NULL;
+    goto out;
 
   iter = mnt_new_iter (MNT_ITER_FORWARD);
   while (mnt_table_next_fs (table, iter, &fs) == 0)
@@ -942,8 +943,9 @@ _g_get_unix_mount_points (void)
 
       return_list = g_list_prepend (return_list, mount_point);
     }
-
   mnt_free_iter (iter);
+
+ out:
   mnt_free_context (ctxt);
 
   return g_list_reverse (return_list);


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