diff options
author | Peter Wu <peter@lekensteyn.nl> | 2014-11-20 15:55:37 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2014-11-26 11:56:16 +0000 |
commit | 90994b0d81ca8e44e6a150c53d2c713fad39c29c (patch) | |
tree | 343aa8ec2c9dee4534d44f0868b5606945f8eb27 /src/up-device-list.c | |
parent | a91d03a3a9310b5d00e65a249aab2241906733bc (diff) | |
download | upower-90994b0d81ca8e44e6a150c53d2c713fad39c29c.tar.gz |
daemon: release resources at shutdown
This makes it easier to find real memory leaks with valgrind. After
calling the up_backend_unplug functions, you cannot restart it with
up_backend_coldplug since the lists are cleared.
Tested with Linux only (not on *BSD; dummy compiles).
https://bugs.freedesktop.org/show_bug.cgi?id=82659
Diffstat (limited to 'src/up-device-list.c')
-rw-r--r-- | src/up-device-list.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/up-device-list.c b/src/up-device-list.c index da5555b..b95925a 100644 --- a/src/up-device-list.c +++ b/src/up-device-list.c @@ -130,6 +130,37 @@ up_device_list_remove (UpDeviceList *list, GObject *device) } /** + * up_device_list_remove_cb: + **/ +static gboolean +up_device_list_remove_all_cb (gpointer key, gpointer value, gpointer user_data) +{ + return TRUE; +} + +/** + * up_device_list_clear: + * @list: This class instance + * @unref_it: %TRUE if you own a reference to the objects and want to drop it. + * + * Clear the contents of this list. + **/ +void +up_device_list_clear (UpDeviceList *list, gboolean unref_it) +{ + g_return_if_fail (UP_IS_DEVICE_LIST (list)); + + /* caller owns these objects, but wants to destroy them */ + if (unref_it) + g_ptr_array_foreach (list->priv->array, (GFunc) g_object_unref, NULL); + + /* remove all devices from the db */ + g_hash_table_foreach_remove (list->priv->map_native_path_to_device, + up_device_list_remove_all_cb, NULL); + g_ptr_array_set_size (list->priv->array, 0); +} + +/** * up_device_list_get_array: * * This is quick to iterate when we don't have GObject's to resolve |