From 29c5c85f6bf2a163c8713641dba634910ee3cf49 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Wed, 18 May 2016 10:12:25 +0200 Subject: [PATCH 3/3] lib: Remove hidden singleton instance GObject _new constructors should always return a new pointer and not do anything else than g_{object,initable}_new(). Drop the internal up_client_object singleton instance. This simplifies the code and makes the code robust with multiple threads. Side issue in https://bugs.freedesktop.org/show_bug.cgi?id=95350 --- libupower-glib/up-client.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/libupower-glib/up-client.c b/libupower-glib/up-client.c index adc0b9b..330c0ad 100644 --- a/libupower-glib/up-client.c +++ b/libupower-glib/up-client.c @@ -72,7 +72,6 @@ enum { }; static guint signals [UP_CLIENT_LAST_SIGNAL] = { 0 }; -static gpointer up_client_object = NULL; G_DEFINE_TYPE_WITH_CODE (UpClient, up_client, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(G_TYPE_INITABLE, up_client_initable_iface_init)) @@ -511,14 +510,7 @@ up_client_finalize (GObject *object) UpClient * up_client_new_full (GCancellable *cancellable, GError **error) { - if (up_client_object != NULL) { - g_object_ref (up_client_object); - } else { - up_client_object = g_initable_new (UP_TYPE_CLIENT, cancellable, error, NULL); - if (up_client_object) - g_object_add_weak_pointer (up_client_object, &up_client_object); - } - return UP_CLIENT (up_client_object); + return g_initable_new (UP_TYPE_CLIENT, cancellable, error, NULL); } /** -- 2.7.4