From fac8f21e5e111e62571c1e849da6c622c80ffc0a Mon Sep 17 00:00:00 2001 From: Ignacio Casal Quinteiro Date: Thu, 8 Jan 2015 12:04:15 +0100 Subject: Revert "Use __attribute__(cleanup) in more places" This reverts commit cdbd7e6cc165c39580e72ac1415d233f5eaa7101. --- gusb/gusb-context.c | 19 +++++++++++++------ gusb/gusb-self-test.c | 40 ++++++++++++++++++++++++++++------------ tools/gusb-main.c | 33 +++++++++++++++++++++++---------- 3 files changed, 64 insertions(+), 28 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 diff --git a/tools/gusb-main.c b/tools/gusb-main.c index a870760..bb8c3de 100644 --- a/tools/gusb-main.c +++ b/tools/gusb-main.c @@ -103,9 +103,9 @@ gusb_sort_command_name_cb (GUsbCmdItem **item1, GUsbCmdItem **item2) static void gusb_cmd_add (GPtrArray *array, const gchar *name, const gchar *description, GUsbCmdPrivateCb callback) { - GUsbCmdItem *item; + gchar **names; guint i; - _cleanup_strv_free_ gchar **names = NULL; + GUsbCmdItem *item; /* add each one */ names = g_strsplit (name, ",", -1); @@ -122,6 +122,7 @@ gusb_cmd_add (GPtrArray *array, const gchar *name, const gchar *description, GUs item->callback = callback; g_ptr_array_add (array, item); } + g_strfreev (names); } /** @@ -318,10 +319,10 @@ static gboolean gusb_cmd_watch (GUsbCmdPrivate *priv, gchar **values, GError **error) { gboolean ret = TRUE; + GPtrArray *devices; guint i; GUsbDevice *device; GMainLoop *loop; - _cleanup_ptrarray_unref_ GPtrArray *devices = NULL; devices = g_usb_context_get_devices (priv->usb_ctx); for (i = 0; i < devices->len; i++) { @@ -342,6 +343,7 @@ gusb_cmd_watch (GUsbCmdPrivate *priv, gchar **values, GError **error) g_main_loop_run (loop); g_main_loop_unref (loop); + g_ptr_array_unref (devices); return ret; } @@ -351,15 +353,18 @@ gusb_cmd_watch (GUsbCmdPrivate *priv, gchar **values, GError **error) static gboolean gusb_cmd_run (GUsbCmdPrivate *priv, const gchar *command, gchar **values, GError **error) { + gboolean ret = FALSE; guint i; GUsbCmdItem *item; - _cleanup_string_free_ GString *string = NULL; + GString *string; /* find command */ for (i = 0; i < priv->cmd_array->len; i++) { item = g_ptr_array_index (priv->cmd_array, i); - if (g_strcmp0 (item->name, command) == 0) - return item->callback (priv, values, error); + if (g_strcmp0 (item->name, command) == 0) { + ret = item->callback (priv, values, error); + goto out; + } } /* not found */ @@ -371,7 +376,9 @@ gusb_cmd_run (GUsbCmdPrivate *priv, const gchar *command, gchar **values, GError g_string_append_printf (string, " * %s\n", item->name); } g_set_error_literal (error, 1, 0, string->str); - return FALSE; + g_string_free (string, TRUE); +out: + return ret; } /** @@ -382,11 +389,12 @@ main (int argc, char *argv[]) { gboolean ret; gboolean verbose = FALSE; + gchar *cmd_descriptions = NULL; + gchar *options_help = NULL; + GError *error = NULL; gint retval = 0; GUsbCmdPrivate *priv; - _cleanup_free_ gchar *cmd_descriptions = NULL; - _cleanup_free_ gchar *options_help = NULL; - _cleanup_error_free_ GError *error = NULL; + const GOptionEntry options[] = { { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Show extra debugging information", NULL }, @@ -448,6 +456,7 @@ main (int argc, char *argv[]) ret = gusb_cmd_run (priv, argv[1], (gchar**) &argv[2], &error); if (!ret) { g_print ("%s\n", error->message); + g_error_free (error); retval = 1; goto out; } @@ -460,5 +469,9 @@ out: g_option_context_free (priv->context); g_slice_free (GUsbCmdPrivate, priv); } + + /* free state */ + g_free (options_help); + g_free (cmd_descriptions); return retval; } -- cgit v1.2.1