diff options
author | Stef Walter <stefw@collabora.co.uk> | 2011-11-15 18:01:41 +0100 |
---|---|---|
committer | Stef Walter <stefw@collabora.co.uk> | 2011-11-15 18:01:41 +0100 |
commit | c20ca48b9822ff7f2128c5055d13a5abb337c354 (patch) | |
tree | 4381585539ed606b8b84e22cdcee8e911f621862 /gck | |
parent | b22d39cf68a59189572006a21537018e6c5ab4d6 (diff) | |
download | gcr-c20ca48b9822ff7f2128c5055d13a5abb337c354.tar.gz gcr-c20ca48b9822ff7f2128c5055d13a5abb337c354.tar.bz2 gcr-c20ca48b9822ff7f2128c5055d13a5abb337c354.zip |
gck: Fix problem where gck_slot_open_session_async() leaked objects
* Held a reference to the session and result, which kept the module
Diffstat (limited to 'gck')
-rw-r--r-- | gck/gck-mock.c | 1 | ||||
-rw-r--r-- | gck/gck-slot.c | 11 | ||||
-rw-r--r-- | gck/tests/test-gck-session.c | 4 |
3 files changed, 14 insertions, 2 deletions
diff --git a/gck/gck-mock.c b/gck/gck-mock.c index fc6cd2f..a6a60b2 100644 --- a/gck/gck-mock.c +++ b/gck/gck-mock.c @@ -333,6 +333,7 @@ gck_mock_C_Initialize (CK_VOID_PTR pInitArgs) gck_attributes_add_string (attrs, CKA_GNOME_UNIQUE, "unique4"); g_hash_table_insert (the_objects, GUINT_TO_POINTER (PUBLIC_KEY_PREFIX), attrs); + logged_in = FALSE; initialized = TRUE; return CKR_OK; } diff --git a/gck/gck-slot.c b/gck/gck-slot.c index c26ed02..f55fb50 100644 --- a/gck/gck-slot.c +++ b/gck/gck-slot.c @@ -1025,9 +1025,11 @@ on_open_session_complete (GObject *source, { GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data); GError *error = NULL; + GObject *session; - if (g_async_initable_new_finish (G_ASYNC_INITABLE (source), result, &error)) - g_simple_async_result_set_op_res_gpointer (res, g_object_ref (source), g_object_unref); + session = g_async_initable_new_finish (G_ASYNC_INITABLE (source), result, &error); + if (session != NULL) + g_simple_async_result_set_op_res_gpointer (res, session, g_object_unref); else g_simple_async_result_take_error (res, error); @@ -1063,6 +1065,9 @@ gck_slot_open_session_full_async (GckSlot *self, { GSimpleAsyncResult *res; + g_return_if_fail (GCK_IS_SLOT (self)); + g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); + res = g_simple_async_result_new (G_OBJECT (self), callback, user_data, gck_slot_open_session_full_async); @@ -1074,6 +1079,8 @@ gck_slot_open_session_full_async (GckSlot *self, "opening-flags", pkcs11_flags, "app-data", app_data, NULL); + + g_object_unref (res); } /** diff --git a/gck/tests/test-gck-session.c b/gck/tests/test-gck-session.c index 7f9e576..24323ff 100644 --- a/gck/tests/test-gck-session.c +++ b/gck/tests/test-gck-session.c @@ -72,6 +72,7 @@ teardown (Test *test, gconstpointer unused) g_object_unref (test->session); g_object_unref (test->slot); g_object_unref (test->module); + g_assert (!G_IS_OBJECT (test->module)); } static void @@ -138,7 +139,10 @@ test_open_close_session (Test *test, gconstpointer unused) g_assert (GCK_IS_SESSION (sess)); g_object_unref (result); + g_assert (!G_IS_OBJECT (result)); + g_object_unref (sess); + g_assert (!G_IS_OBJECT (sess)); } static void |