[gnome-settings-daemon] smartcard: Fix crash on startup
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] smartcard: Fix crash on startup
- Date: Tue, 19 Apr 2016 09:34:53 +0000 (UTC)
commit 0e0ce100ac682b5096a29f89701da9944a80eaa4
Author: Bastien Nocera <hadess hadess net>
Date: Mon Apr 18 17:18:02 2016 +0200
smartcard: Fix crash on startup
A number of async helpers were using the
gsd_smartcard_utils_finish_boolean_task() function, that would unref the
GTask when the _finish() function was called. The idiomatic way (and the way
the GTask examples show) to unref the GTask is after calling
g_task_return_*().
The g_task_return_*() call will take care of holding a reference to the
GTask until the _finish() call is made and done.
https://bugzilla.gnome.org/show_bug.cgi?id=765203
plugins/smartcard/gsd-smartcard-manager.c | 16 ++++++++--------
plugins/smartcard/gsd-smartcard-service.c | 6 ++++--
plugins/smartcard/gsd-smartcard-utils.c | 16 ----------------
plugins/smartcard/gsd-smartcard-utils.h | 4 ----
4 files changed, 12 insertions(+), 30 deletions(-)
---
diff --git a/plugins/smartcard/gsd-smartcard-manager.c b/plugins/smartcard/gsd-smartcard-manager.c
index fada4cc..5300965 100644
--- a/plugins/smartcard/gsd-smartcard-manager.c
+++ b/plugins/smartcard/gsd-smartcard-manager.c
@@ -344,8 +344,6 @@ watch_smartcards_from_driver_async (GsdSmartcardManager *self,
G_UNLOCK (gsd_smartcards_watch_tasks);
g_task_run_in_thread (task, (GTaskThreadFunc) watch_smartcards_from_driver);
-
- g_object_unref (task);
}
static gboolean
@@ -353,7 +351,7 @@ register_driver_finish (GsdSmartcardManager *self,
GAsyncResult *result,
GError **error)
{
- return gsd_smartcard_utils_finish_boolean_task (G_OBJECT (self), result, error);
+ return g_task_propagate_boolean (G_TASK (result), error);
}
static void
@@ -365,10 +363,13 @@ on_driver_registered (GsdSmartcardManager *self,
if (!register_driver_finish (self, result, &error)) {
g_task_return_error (task, error);
+ g_object_unref (task);
return;
}
g_task_return_boolean (task, TRUE);
+
+ g_object_unref (task);
}
static void
@@ -487,7 +488,7 @@ activate_driver_async_finish (GsdSmartcardManager *self,
GAsyncResult *result,
GError **error)
{
- return gsd_smartcard_utils_finish_boolean_task (G_OBJECT (self), result, error);
+ return g_task_propagate_boolean (G_TASK (result), error);
}
static void
@@ -578,7 +579,7 @@ activate_all_drivers_async_finish (GsdSmartcardManager *self,
GAsyncResult *result,
GError **error)
{
- return gsd_smartcard_utils_finish_boolean_task (G_OBJECT (self), result, error);
+ return g_task_propagate_boolean (G_TASK (result), error);
}
static void
@@ -608,6 +609,7 @@ on_all_drivers_activated (GsdSmartcardManager *self,
}
g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
}
static void
@@ -647,8 +649,6 @@ watch_smartcards_async (GsdSmartcardManager *self,
task = g_task_new (self, cancellable, callback, user_data);
g_task_run_in_thread (task, (GTaskThreadFunc) watch_smartcards);
-
- g_object_unref (task);
}
static gboolean
@@ -656,7 +656,7 @@ watch_smartcards_async_finish (GsdSmartcardManager *self,
GAsyncResult *result,
GError **error)
{
- return gsd_smartcard_utils_finish_boolean_task (G_OBJECT (self), result, error);
+ return g_task_propagate_boolean (G_TASK (result), error);
}
static void
diff --git a/plugins/smartcard/gsd-smartcard-service.c b/plugins/smartcard/gsd-smartcard-service.c
index fc46d03..24982a2 100644
--- a/plugins/smartcard/gsd-smartcard-service.c
+++ b/plugins/smartcard/gsd-smartcard-service.c
@@ -587,6 +587,7 @@ on_main_thread_to_register_new_token (GTask *task)
G_UNLOCK (gsd_smartcard_tokens);
g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
return G_SOURCE_REMOVE;
}
@@ -637,7 +638,7 @@ register_new_token_in_main_thread_finish (GsdSmartcardService *self,
GAsyncResult *result,
GError **error)
{
- return gsd_smartcard_utils_finish_boolean_task (G_OBJECT (self), result, error);
+ return g_task_propagate_boolean (G_TASK (result), error);
}
static void
@@ -692,6 +693,7 @@ on_main_thread_to_synchronize_token (GTask *task)
synchronize_token_now (self, operation->card_slot);
g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
return G_SOURCE_REMOVE;
}
@@ -701,7 +703,7 @@ synchronize_token_in_main_thread_finish (GsdSmartcardService *self,
GAsyncResult *result,
GError **error)
{
- return gsd_smartcard_utils_finish_boolean_task (G_OBJECT (self), result, error);
+ return g_task_propagate_boolean (G_TASK (result), error);
}
static void
diff --git a/plugins/smartcard/gsd-smartcard-utils.c b/plugins/smartcard/gsd-smartcard-utils.c
index 096276e..6b9461b 100644
--- a/plugins/smartcard/gsd-smartcard-utils.c
+++ b/plugins/smartcard/gsd-smartcard-utils.c
@@ -172,19 +172,3 @@ gsd_smartcard_utils_escape_object_path (const char *unescaped_string)
return object_path;
}
-
-gboolean
-gsd_smartcard_utils_finish_boolean_task (GObject *object,
- GAsyncResult *result,
- GError **error)
-{
- gboolean return_value;
-
- g_return_val_if_fail (g_task_is_valid (result, object), FALSE);
-
- return_value = g_task_propagate_boolean (G_TASK (result), error);
-
- g_object_unref (G_OBJECT (result));
-
- return return_value;
-}
diff --git a/plugins/smartcard/gsd-smartcard-utils.h b/plugins/smartcard/gsd-smartcard-utils.h
index 8559072..c7822bf 100644
--- a/plugins/smartcard/gsd-smartcard-utils.h
+++ b/plugins/smartcard/gsd-smartcard-utils.h
@@ -28,10 +28,6 @@ void gsd_smartcard_utils_register_error_domain (GQuark e
GType error_enum);
char * gsd_smartcard_utils_escape_object_path (const char *unescaped_string);
-gboolean gsd_smartcard_utils_finish_boolean_task (GObject *object,
- GAsyncResult *result,
- GError **error);
-
G_END_DECLS
#endif /* __GSD_SMARTCARD_MANAGER_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]