[gvfs] ProxyVolumeMonitor: Don't leak a GVfsDBusDaemon



commit 12b238a38739d1bf01f021e448c6a1f5623f7e9b
Author: Matthew Leeds <matthew leeds endlessm com>
Date:   Fri Jul 12 14:32:48 2019 -0700

    ProxyVolumeMonitor: Don't leak a GVfsDBusDaemon
    
    In g_proxy_volume_monitor_register() we create a GVfsDBusDaemon object
    (which is also of type GDBusProxy) but never free it. This causes there
    to be a dangling reference to the singleton GDBusConnection object used
    by the GDBusProxy for the rest of the lifetime of a process that uses a
    gvfs function such as g_file_new_for_path(). With the recent changes I
    made to GLib[1], that extra reference leads to a warning after a 30
    second delay in g_test_dbus_down().
    
    So this commit frees the GVfsDBusDaemon object after it has served its
    purpose in g_proxy_volume_monitor_register(), which fixes the test
    failure I'm seeing in another project.
    
    This is consistent with how we handle GDBusProxy objects in most of the
    rest of gvfs, but there are two places where they are leaked:
    1. in g_proxy_volume_monitor_constructor(), but that object appears to
    be intended to live forever, so it's unclear what should be done there
    2. in meta_tree_get_metadata_proxy(), but there the proxy is a static
    variable so it's unclear when it should be freed
    
    If you try to reproduce this leak, note that if gio takes its "lazy
    loading" code path in g_io_modules_scan_all_in_directory_with_scope(),
    this g_proxy_volume_monitor_register() function may not be executed. So
    I had to change an if condition so that we would always call
    g_type_module_use(). That lazy loading only happened when I built and
    installed gvfs myself rather than using the distribution's package.
    
    [1] https://gitlab.gnome.org/GNOME/glib/merge_requests/963

 monitor/proxy/gproxyvolumemonitor.c | 2 ++
 1 file changed, 2 insertions(+)
---
diff --git a/monitor/proxy/gproxyvolumemonitor.c b/monitor/proxy/gproxyvolumemonitor.c
index 9b2a973c..3237a3a5 100644
--- a/monitor/proxy/gproxyvolumemonitor.c
+++ b/monitor/proxy/gproxyvolumemonitor.c
@@ -1497,6 +1497,8 @@ g_proxy_volume_monitor_register (GIOModule *module)
                 g_debug ("Error: %s\n", error->message);
               g_error_free (error);
             }
+
+          g_clear_object (&proxy);
         }
       else
         {


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