[gnome-multi-writer] Fix crash when libusb context creation fails
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-multi-writer] Fix crash when libusb context creation fails
- Date: Fri, 9 Jan 2015 14:21:48 +0000 (UTC)
commit 4e5873e08d5d2e84c2fbd8b1ec0de7e673baf35e
Author: Richard Hughes <richard hughsie com>
Date: Fri Jan 9 14:21:25 2015 +0000
Fix crash when libusb context creation fails
src/gmw-main.c | 16 +++++++++++++---
1 files changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/src/gmw-main.c b/src/gmw-main.c
index e17b0be..92ddb24 100644
--- a/src/gmw-main.c
+++ b/src/gmw-main.c
@@ -1249,8 +1249,13 @@ gmw_udisks_find_usb_device (GmwPrivate *priv, GmwDevice *device)
{
guint8 busnum;
guint8 devnum;
+ _cleanup_error_free_ GError *error = NULL;
_cleanup_object_unref_ GUsbDevice *usb_device = NULL;
+ /* failed to load GUsb */
+ if (priv->usb_ctx == NULL)
+ return;
+
/* find the USB device using GUsb */
if (gmw_device_get_sysfs_path (device) == NULL)
return;
@@ -1263,9 +1268,9 @@ gmw_udisks_find_usb_device (GmwPrivate *priv, GmwDevice *device)
usb_device = g_usb_context_find_by_bus_address (priv->usb_ctx,
busnum,
devnum,
- NULL);
+ &error);
if (usb_device == NULL) {
- g_warning ("Failed to find %02x:%02x", busnum, devnum);
+ g_warning ("%s", error->message);
return;
}
gmw_device_set_usb_device (device, usb_device);
@@ -1557,7 +1562,12 @@ main (int argc, char **argv)
gmw_thread_pool_sort_func,
priv);
priv->devices = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
- priv->usb_ctx = g_usb_context_new (NULL);
+ priv->usb_ctx = g_usb_context_new (&error);
+ if (priv->usb_ctx == NULL) {
+ status = EXIT_FAILURE;
+ g_print ("Failed to load libusb: %s\n", error->message);
+ goto out;
+ }
/* connect to UDisks */
udisks_client_new (NULL, gmw_udisks_client_connect_cb, priv);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]