[gnome-control-center] common: Fix leak of GUdevDevice



commit dac8fd64cd3f48e5fb0bab0842a5c027d8e98a12
Author: Victor Toso <victortoso redhat com>
Date:   Tue Oct 12 11:48:55 2021 +0200

    common: Fix leak of GUdevDevice
    
    The add_device() check for g_udev_device_get_parent() was leaking (see
    below). As this is actually used in create_device(), I'm passing it as
    argument to avoid a second call to that function.
    
     > 34,175 (1,080 direct, 33,095 indirect) bytes in 27 blocks are definitely lost in loss record 19,729 of 
19,758
     >    at 0x4A7A337: g_type_create_instance (gtype.c:1907)
     >    by 0x4A61CAC: g_object_new_internal (gobject.c:1945)
     >    by 0x4A62C7C: g_object_new_with_properties (gobject.c:2114)
     >    by 0x4A63780: g_object_new (gobject.c:1785)
     >    by 0x5EA5A6A: _g_udev_device_new (gudevdevice.c:132)
     >    by 0x4B6D24: add_device (gsd-device-manager.c:447)
     >    by 0x4B6FBF: gsd_device_manager_init (gsd-device-manager.c:517)
     >    by 0x4A7A288: g_type_create_instance (gtype.c:1929)
     >    by 0x4A61CAC: g_object_new_internal (gobject.c:1945)
     >    by 0x4A62C7C: g_object_new_with_properties (gobject.c:2114)
     >    by 0x4A63780: g_object_new (gobject.c:1785)
     >    by 0x4B7075: gsd_device_manager_get (gsd-device-manager.c:533)

 panels/common/gsd-device-manager.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
---
diff --git a/panels/common/gsd-device-manager.c b/panels/common/gsd-device-manager.c
index df24ef7cd..6283ccbf7 100644
--- a/panels/common/gsd-device-manager.c
+++ b/panels/common/gsd-device-manager.c
@@ -400,14 +400,10 @@ device_is_evdev (GUdevDevice *device)
 }
 
 static GsdDevice *
-create_device (GUdevDevice *udev_device)
+create_device (GUdevDevice *udev_device, GUdevDevice *parent)
 {
        const gchar *vendor, *product, *name, *group;
        guint width, height;
-       g_autoptr(GUdevDevice) parent = NULL;
-
-       parent = g_udev_device_get_parent (udev_device);
-       g_assert (parent != NULL);
 
        name = g_udev_device_get_sysfs_attr (parent, "name");
        vendor = g_udev_device_get_property (udev_device, "ID_VENDOR_ID");
@@ -440,7 +436,7 @@ add_device (GsdDeviceManager *manager,
            GUdevDevice      *udev_device)
 {
         GsdDeviceManagerPrivate *priv = gsd_device_manager_get_instance_private (manager);
-       GUdevDevice *parent;
+       g_autoptr(GUdevDevice) parent = NULL;
        GsdDevice *device;
        const gchar *syspath;
 
@@ -449,7 +445,7 @@ add_device (GsdDeviceManager *manager,
        if (!parent)
                return;
 
-       device = create_device (udev_device);
+       device = create_device (udev_device, parent);
        syspath = g_udev_device_get_sysfs_path (udev_device);
        g_hash_table_insert (priv->devices, g_strdup (syspath), device);
        g_signal_emit_by_name (manager, "device-added", device);


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