[liboobs] Check for error when calling libhal_find_device_by_capability()
- From: Milan Bouchet-Valat <milanbv src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [liboobs] Check for error when calling libhal_find_device_by_capability()
- Date: Wed, 2 Dec 2009 14:12:02 +0000 (UTC)
commit 56ef4e6742a6ba4f2cba7608d89d39ef39f229e6
Author: Milan Bouchet-Valat <nalimilan club fr>
Date: Wed Dec 2 15:07:34 2009 +0100
Check for error when calling libhal_find_device_by_capability()
Sometimes this function returns NULL without setting n_devices to 0, which causes us to crash. Anyway, better report the error to the console via a warning. See https://bugs.launchpad.net/ubuntu/+source/gnome-system-tools/+bug/490694.
oobs/oobs-ifacesconfig.c | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/oobs/oobs-ifacesconfig.c b/oobs/oobs-ifacesconfig.c
index 53f24cd..f910b93 100644
--- a/oobs/oobs-ifacesconfig.c
+++ b/oobs/oobs-ifacesconfig.c
@@ -184,11 +184,20 @@ hal_context_get_initial_devices (LibHalContext *context)
GHashTable *devices;
gint i, n_devices;
gchar **udis;
+ DBusError error;
devices = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free, NULL);
- udis = libhal_find_device_by_capability (context, "net", &n_devices, NULL);
+ dbus_error_init(&error);
+ udis = libhal_find_device_by_capability (context, "net", &n_devices, &error);
+
+ /* In case an error occurred, udis would be NULL, possibly leading to crash */
+ if (dbus_error_is_set (&error)) {
+ g_warning ("Could not find any network device on the system: %s.",
+ error.message);
+ return devices;
+ }
for (i = 0; i < n_devices; i++)
g_hash_table_insert (devices, g_strdup (udis[i]), GINT_TO_POINTER (TRUE));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]