[gnome-bluetooth/wip/hadess/lib-changes] settings: Simplify memory management



commit e5a95e509131b997bd8973352af3d4ad27adbdb9
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Nov 25 12:48:54 2021 +0100

    settings: Simplify memory management

 lib/bluetooth-settings-obexpush.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)
---
diff --git a/lib/bluetooth-settings-obexpush.c b/lib/bluetooth-settings-obexpush.c
index 1b07f3ec..fe7e369b 100644
--- a/lib/bluetooth-settings-obexpush.c
+++ b/lib/bluetooth-settings-obexpush.c
@@ -323,23 +323,21 @@ on_check_bonded_or_ask_session_acquired (GObject *object,
                                         gpointer user_data)
 {
        GDBusMethodInvocation *invocation = user_data;
-       GDBusProxy *session;
-       GError *error = NULL;
+       g_autoptr(GDBusProxy) session = NULL;
+       g_autoptr(GError) error = NULL;
        GVariant *v;
-       char *device, *adapter, *name;
+       g_autofree char *device = NULL;
+       g_autofree char *adapter = NULL;
+       g_autofree char *name = NULL;
        gboolean paired;
 
        session = g_dbus_proxy_new_for_bus_finish (res, &error);
 
        if (!session) {
                g_debug ("Failed to create a proxy for the session: %s", error->message);
-               g_clear_error (&error);
                goto out;
        }
 
-       device = NULL;
-       adapter = NULL;
-
        /* obexd puts the remote device in Destination and our adapter
         * in Source */
        v = g_dbus_proxy_get_cached_property (session, "Destination");
@@ -354,31 +352,22 @@ on_check_bonded_or_ask_session_acquired (GObject *object,
                g_variant_unref (v);
        }
 
-       g_object_unref (session);
-
        if (!device || !adapter) {
                g_debug ("Could not get remote device for the transfer");
-               g_free (device);
-               g_free (adapter);
                goto out;
        }
 
-       name = NULL;
        paired = get_paired_for_address (adapter, device, &name);
-       g_free (device);
-       g_free (adapter);
 
        if (paired) {
                g_debug ("Remote device '%s' is paired, auto-accepting the transfer", name);
                g_dbus_method_invocation_return_value (invocation,
                                                       g_variant_new ("(s)", g_object_get_data (G_OBJECT 
(invocation), "temp-filename")));
-               g_free (name);
                return;
        } else {
                ask_user (invocation,
                          g_object_get_data (G_OBJECT (invocation), "filename"),
                          name ? name : device);
-               g_free (name);
                return;
        }
 


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