diff options
author | Ignacio Casal Quinteiro <icq@gnome.org> | 2015-01-08 12:04:15 +0100 |
---|---|---|
committer | Ignacio Casal Quinteiro <icq@gnome.org> | 2015-01-08 12:04:15 +0100 |
commit | fac8f21e5e111e62571c1e849da6c622c80ffc0a (patch) | |
tree | 0056d628ba74b7e605afe903acb1da797f7baaee /gusb | |
parent | 37f331b24f51f6b9b2cb44c384a2bd8c749e266e (diff) | |
download | gusb-fac8f21e5e111e62571c1e849da6c622c80ffc0a.tar.gz |
Revert "Use __attribute__(cleanup) in more places"
This reverts commit cdbd7e6cc165c39580e72ac1415d233f5eaa7101.
Diffstat (limited to 'gusb')
-rw-r--r-- | gusb/gusb-context.c | 19 | ||||
-rw-r--r-- | gusb/gusb-self-test.c | 40 |
2 files changed, 41 insertions, 18 deletions
diff --git a/gusb/gusb-context.c b/gusb/gusb-context.c index 7579d2e..1334b16 100644 --- a/gusb/gusb-context.c +++ b/gusb/gusb-context.c @@ -274,11 +274,11 @@ static void g_usb_context_add_device (GUsbContext *context, struct libusb_device *dev) { + GUsbDevice *device = NULL; GUsbContextPrivate *priv = context->priv; guint8 bus; guint8 address; - _cleanup_error_free_ GError *error = NULL; - _cleanup_object_unref_ GUsbDevice *device = NULL; + GError *error = NULL; /* does any existing device exist */ bus = libusb_get_bus_number (dev); @@ -288,7 +288,7 @@ g_usb_context_add_device (GUsbContext *context, device = g_usb_context_find_by_bus_address (context, bus, address, NULL); if (device != NULL) { g_debug ("%i:%i already exists", bus, address); - return; + goto out; } /* add the device */ @@ -296,20 +296,24 @@ g_usb_context_add_device (GUsbContext *context, if (device == NULL) { g_debug ("There was a problem creating the device: %s", error->message); - return; + g_error_free (error); + goto out; } g_ptr_array_add (priv->devices, g_object_ref (device)); g_usb_context_emit_device_add (context, device); +out: + if (device != NULL) + g_object_unref (device); } static void g_usb_context_remove_device (GUsbContext *context, struct libusb_device *dev) { + GUsbDevice *device = NULL; GUsbContextPrivate *priv = context->priv; guint8 bus; guint8 address; - _cleanup_object_unref_ GUsbDevice *device = NULL; /* does any existing device exist */ bus = libusb_get_bus_number (dev); @@ -321,6 +325,7 @@ g_usb_context_remove_device (GUsbContext *context, } g_usb_context_emit_device_remove (context, device); g_ptr_array_remove (priv->devices, device); + g_object_unref (device); } static int @@ -347,13 +352,13 @@ g_usb_context_hotplug_cb (struct libusb_context *ctx, static void g_usb_context_rescan (GUsbContext *context) { + GList *existing_devices = NULL; GList *l; GUsbDevice *device; GUsbContextPrivate *priv = context->priv; gboolean found; guint i; libusb_device **dev_list = NULL; - _cleanup_list_free_ GList *existing_devices = NULL; /* copy to a context so we can remove from the array */ for (i = 0; i < priv->devices->len; i++) { @@ -382,6 +387,8 @@ g_usb_context_rescan (GUsbContext *context) libusb_get_device_list (priv->ctx, &dev_list); for (i = 0; dev_list && dev_list[i]; i++) g_usb_context_add_device (context, dev_list[i]); + + g_list_free (existing_devices); libusb_free_device_list (dev_list, 1); } diff --git a/gusb/gusb-self-test.c b/gusb/gusb-self-test.c index 3ad0199..5eaee0a 100644 --- a/gusb/gusb-self-test.c +++ b/gusb/gusb-self-test.c @@ -75,13 +75,15 @@ gusb_context_lookup_func (void) static void gusb_context_func (void) { + GUsbContext *ctx; GError *error = NULL; GPtrArray *array; guint old_number_of_devices; guint8 bus, address; GUsbDevice *device; + gchar *manufacturer; + gchar *product; guint i; - _cleanup_object_unref_ GUsbContext *ctx = NULL; ctx = g_usb_context_new (&error); g_assert_no_error (error); @@ -98,8 +100,6 @@ gusb_context_func (void) /* Print a list (also excercising various bits of g_usb_device) */ g_print ("\n"); for (i = 0; i < array->len; i++) { - _cleanup_free_ gchar *manufacturer = NULL; - _cleanup_free_ gchar *product = NULL; device = G_USB_DEVICE (g_ptr_array_index (array, i)); g_assert_cmpint (g_usb_device_get_vid (device), >, 0x0000); @@ -128,6 +128,9 @@ gusb_context_func (void) g_usb_device_get_pid (device), manufacturer ? manufacturer : "", product ? product : ""); + + g_free (manufacturer); + g_free (product); } g_ptr_array_unref (array); @@ -161,17 +164,19 @@ gusb_context_func (void) G_USB_DEVICE_ERROR_NO_DEVICE); g_assert (device == NULL); g_clear_error (&error); + + g_object_unref (ctx); } static void gusb_device_huey_func (void) { + GUsbContext *ctx; + GError *error = NULL; + GUsbDevice *device; gboolean ret; GCancellable *cancellable = NULL; const gchar request[8] = { 0x0e, 'G', 'r', 'M', 'b', 'k', 'e', 'd' }; - _cleanup_error_free_ GError *error = NULL; - _cleanup_object_unref_ GUsbContext *ctx = NULL; - _cleanup_object_unref_ GUsbDevice *device = NULL; ctx = g_usb_context_new (&error); g_assert_no_error (error); @@ -188,7 +193,8 @@ gusb_device_huey_func (void) error->domain == G_USB_DEVICE_ERROR && error->code == G_USB_DEVICE_ERROR_NO_DEVICE) { g_print ("No device detected!\n"); - return; + g_error_free (error); + goto out; } g_assert_no_error (error); g_assert (device != NULL); @@ -269,6 +275,10 @@ gusb_device_huey_func (void) ret = g_usb_device_close (device, &error); g_assert_no_error (error); g_assert (ret); + + g_object_unref (device); +out: + g_object_unref (ctx); } typedef struct { @@ -305,14 +315,15 @@ g_usb_test_button_pressed_cb (GObject *source_object, gpointer user_data) { gboolean ret; + GError *error = NULL; GUsbDeviceAsyncHelper *helper = (GUsbDeviceAsyncHelper *) user_data; - _cleanup_error_free_ GError *error = NULL; ret = g_usb_device_interrupt_transfer_finish (G_USB_DEVICE (source_object), res, &error); if (!ret) { g_error ("%s", error->message); + g_error_free (error); return; } @@ -326,13 +337,13 @@ g_usb_test_button_pressed_cb (GObject *source_object, static void gusb_device_munki_func (void) { + GError *error = NULL; + GUsbContext *ctx; + GUsbDevice *device; gboolean ret; GCancellable *cancellable = NULL; guint8 request[24]; GUsbDeviceAsyncHelper *helper; - _cleanup_error_free_ GError *error = NULL; - _cleanup_object_unref_ GUsbContext *ctx = NULL; - _cleanup_object_unref_ GUsbDevice *device = NULL; ctx = g_usb_context_new (&error); g_assert_no_error (error); @@ -349,7 +360,8 @@ gusb_device_munki_func (void) error->domain == G_USB_DEVICE_ERROR && error->code == G_USB_DEVICE_ERROR_NO_DEVICE) { g_print ("No device detected!\n"); - return; + g_error_free (error); + goto out; } g_assert_no_error (error); g_assert (device != NULL); @@ -446,6 +458,10 @@ gusb_device_munki_func (void) ret = g_usb_device_close (device, &error); g_assert_no_error (error); g_assert (ret); + + g_object_unref (device); +out: + g_object_unref (ctx); } int |