summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgnacio Casal Quinteiro <icq@gnome.org>2014-12-24 12:24:11 +0100
committerIgnacio Casal Quinteiro <icq@gnome.org>2014-12-24 12:24:11 +0100
commit8780c51dc80c239940a5b2074fee37177cf820e8 (patch)
tree2f74811f623dff77c4a6e9642e33c1817367b25e
parentc44f3d68f8f97186bc8607e51c9c606bccb3c832 (diff)
downloadgusb-8780c51dc80c239940a5b2074fee37177cf820e8.tar.gz
context: use dispose since it makes more sense
Basically if there is an error some of those variables might not be set so better check them before finalizing them.
-rw-r--r--gusb/gusb-context.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/gusb/gusb-context.c b/gusb/gusb-context.c
index c495303..5ced2a1 100644
--- a/gusb/gusb-context.c
+++ b/gusb/gusb-context.c
@@ -74,23 +74,26 @@ G_DEFINE_TYPE_WITH_CODE (GUsbContext, g_usb_context, G_TYPE_OBJECT,
g_usb_context_initable_iface_init))
static void
-g_usb_context_finalize (GObject *object)
+g_usb_context_dispose (GObject *object)
{
GUsbContext *context = G_USB_CONTEXT (object);
GUsbContextPrivate *priv = context->priv;
/* this is safe to call even when priv->hotplug_id is unset */
- g_atomic_int_dec_and_test (&priv->thread_event_run);
- libusb_hotplug_deregister_callback (priv->ctx, priv->hotplug_id);
- g_thread_join (priv->thread_event);
+ if (g_atomic_int_dec_and_test (&priv->thread_event_run)) {
+ libusb_hotplug_deregister_callback (priv->ctx, priv->hotplug_id);
+ g_thread_join (priv->thread_event);
+ }
- if (priv->hotplug_poll_id > 0)
+ if (priv->hotplug_poll_id > 0) {
g_source_remove (priv->hotplug_poll_id);
- g_ptr_array_unref (priv->devices);
+ priv->hotplug_poll_id = 0;
+ }
- libusb_exit (priv->ctx);
+ g_clear_pointer (&priv->devices, g_ptr_array_unref);
+ g_clear_pointer (&priv->ctx, libusb_exit);
- G_OBJECT_CLASS (g_usb_context_parent_class)->finalize (object);
+ G_OBJECT_CLASS (g_usb_context_parent_class)->dispose (object);
}
static void
@@ -141,9 +144,9 @@ g_usb_context_class_init (GUsbContextClass *klass)
GParamSpec *pspec;
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = g_usb_context_finalize;
- object_class->get_property = g_usb_context_get_property;
- object_class->set_property = g_usb_context_set_property;
+ object_class->dispose = g_usb_context_dispose;
+ object_class->get_property = g_usb_context_get_property;
+ object_class->set_property = g_usb_context_set_property;
/**
* GUsbContext:libusb_context: