diff options
author | Peter Wu <lekensteyn@gmail.com> | 2013-08-22 17:37:31 +0200 |
---|---|---|
committer | Martin Pitt <martinpitt@gnome.org> | 2013-09-03 08:31:27 +0200 |
commit | cdeaf166297ac313e42594b4350a00638ff9ef58 (patch) | |
tree | a63c3c37fc6d2effe8a2e417fc7c1008de1eca32 /src/linux | |
parent | dda9bc21e51d0b379eb800f911856683816166eb (diff) | |
download | upower-cdeaf166297ac313e42594b4350a00638ff9ef58.tar.gz |
hidpp: fix memleak while coldplugging
The device returned by g_udev_device_get_parent must be freed by the
caller.
Signed-off-by: Peter Wu <lekensteyn@gmail.com>
Diffstat (limited to 'src/linux')
-rw-r--r-- | src/linux/up-device-unifying.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/linux/up-device-unifying.c b/src/linux/up-device-unifying.c index 8ebf946..830fa32 100644 --- a/src/linux/up-device-unifying.c +++ b/src/linux/up-device-unifying.c @@ -188,13 +188,19 @@ up_device_unifying_coldplug (UpDevice *device) client = g_udev_client_new (NULL); hidraw_list = g_udev_client_query_by_subsystem (client, "hidraw"); for (l = hidraw_list; l != NULL; l = l->next) { + gboolean receiver_found = FALSE; + if (g_strcmp0 (type, "lg-wireless") == 0) { - gboolean receiver_found = FALSE; const gchar *filename; GDir* dir; + GUdevDevice *parent_dev; + + parent_dev = g_udev_device_get_parent(l->data); + receiver_found = g_strcmp0 (g_udev_device_get_sysfs_path (native), + g_udev_device_get_sysfs_path(parent_dev)) == 0; + g_object_unref (parent_dev); - if (g_strcmp0 (g_udev_device_get_sysfs_path (native), - g_udev_device_get_sysfs_path(g_udev_device_get_parent(l->data))) != 0) + if (!receiver_found) continue; /* hidraw device which exposes hiddev interface is our receiver */ @@ -213,16 +219,20 @@ up_device_unifying_coldplug (UpDevice *device) } } g_dir_close(dir); - - if (!receiver_found) - continue; } else { - if (g_strcmp0 (g_udev_device_get_sysfs_path (parent), - g_udev_device_get_sysfs_path(g_udev_device_get_parent(l->data))) != 0) - continue; + GUdevDevice *parent_dev; + + /* Unifying devices are located under their receiver */ + parent_dev = g_udev_device_get_parent(l->data); + receiver_found = g_strcmp0 (g_udev_device_get_sysfs_path (parent), + g_udev_device_get_sysfs_path(parent_dev)) == 0; + g_object_unref (parent_dev); + } + + if (receiver_found) { + receiver = g_object_ref (l->data); + break; } - receiver = g_object_ref (l->data); - break; } if (receiver == NULL) { g_debug ("Unable to find an hidraw device for Unifying receiver"); |