summaryrefslogtreecommitdiff
path: root/gck
diff options
context:
space:
mode:
authorStef Walter <stefw@collabora.co.uk>2011-11-17 15:26:55 +0100
committerStef Walter <stefw@collabora.co.uk>2011-11-21 10:28:27 +0100
commitf3b9d46c75675e9b4b451164dd32ed9b1af0dfb1 (patch)
tree5b66cf37d54e3b447e3087cc27b03eeb7ae332f7 /gck
parent97cd79171dfbba24394f070f3946b20c2d518d2d (diff)
downloadgcr-f3b9d46c75675e9b4b451164dd32ed9b1af0dfb1.tar.gz
gcr-f3b9d46c75675e9b4b451164dd32ed9b1af0dfb1.tar.bz2
gcr-f3b9d46c75675e9b4b451164dd32ed9b1af0dfb1.zip
Add valgrind memory checking and fix up errors
* This is especially necessary after migrating to EggBytes since it's reference counted and an easy sourc of memory leaks * Remove threading from testing framework, as gcr isn't threadsafe in all parts. * Fix bugs discovered in memory checking. * Fix up some of the testing stuff.
Diffstat (limited to 'gck')
-rw-r--r--gck/Makefile.am3
-rw-r--r--gck/gck-interaction.c1
-rw-r--r--gck/gck-mock.c6
-rw-r--r--gck/gck-session.c1
-rw-r--r--gck/tests/Makefile.am4
-rw-r--r--gck/tests/test-gck-attributes.c2
-rw-r--r--gck/tests/test-gck-crypto.c31
-rw-r--r--gck/tests/test-gck-enumerator.c22
-rw-r--r--gck/tests/test-gck-module.c3
-rw-r--r--gck/tests/test-gck-modules.c2
-rw-r--r--gck/tests/test-gck-object.c6
-rw-r--r--gck/tests/test-gck-session.c12
-rw-r--r--gck/tests/test-gck-slot.c2
-rw-r--r--gck/tests/test-gck-uri.c1
14 files changed, 78 insertions, 18 deletions
diff --git a/gck/Makefile.am b/gck/Makefile.am
index 5856f0f..9d83836 100644
--- a/gck/Makefile.am
+++ b/gck/Makefile.am
@@ -144,6 +144,9 @@ check-symbols: gck-expected.abi gck-actual.abi
check-local: check-symbols
+check-memory:
+ make -C tests check-memory
+
EXTRA_DIST = \
gck.pc.in \
gck-marshal.list \
diff --git a/gck/gck-interaction.c b/gck/gck-interaction.c
index 33d5ad3..ef61e6b 100644
--- a/gck/gck-interaction.c
+++ b/gck/gck-interaction.c
@@ -132,6 +132,7 @@ _gck_interaction_ask_password (GTlsInteraction *interaction,
g_signal_emit_by_name (self->module, "authenticate-object", key,
g_tls_password_get_description (password),
&value, &ret);
+ g_object_unref (key);
}
if (ret) {
diff --git a/gck/gck-mock.c b/gck/gck-mock.c
index a6a60b2..a1fdba9 100644
--- a/gck/gck-mock.c
+++ b/gck/gck-mock.c
@@ -721,13 +721,17 @@ gck_mock_C_SetPIN (CK_SESSION_HANDLE hSession, CK_UTF8CHAR_PTR pOldPin,
CK_ULONG ulOldLen, CK_UTF8CHAR_PTR pNewPin, CK_ULONG ulNewLen)
{
Session *session;
+ gboolean match;
gchar *old;
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
g_return_val_if_fail (session, CKR_SESSION_HANDLE_INVALID);
old = g_strndup ((gchar*)pOldPin, ulOldLen);
- if (!old || !g_str_equal (old, the_pin))
+ match = old && g_str_equal (old, the_pin);
+ g_free (old);
+
+ if (!match)
return CKR_PIN_INCORRECT;
g_free (the_pin);
diff --git a/gck/gck-session.c b/gck/gck-session.c
index 13c1569..9e63a3b 100644
--- a/gck/gck-session.c
+++ b/gck/gck-session.c
@@ -1497,6 +1497,7 @@ free_find_objects (FindObjects *args)
{
gck_attributes_unref (args->attrs);
g_free (args->objects);
+ g_free (args);
}
static CK_RV
diff --git a/gck/tests/Makefile.am b/gck/tests/Makefile.am
index 113813e..72dfde3 100644
--- a/gck/tests/Makefile.am
+++ b/gck/tests/Makefile.am
@@ -1,3 +1,4 @@
+include $(top_srcdir)/Makefile.decl
INCLUDES = \
-I$(top_builddir) \
@@ -5,6 +6,7 @@ INCLUDES = \
-DSRCDIR="\"@abs_srcdir@\"" \
-DBUILDDIR="\"@abs_builddir@\"" \
-DGCK_API_SUBJECT_TO_CHANGE \
+ -DG_LOG_DOMAIN=\"Gck\" \
$(GLIB_CFLAGS)
LDADD = \
@@ -42,6 +44,8 @@ test: $(TEST_PROGS)
check-local: test
+check-memory: perform-memcheck
+
all-local: $(check_PROGRAMS)
lib_LTLIBRARIES = libmock-test-module.la
diff --git a/gck/tests/test-gck-attributes.c b/gck/tests/test-gck-attributes.c
index bf2fc03..504844e 100644
--- a/gck/tests/test-gck-attributes.c
+++ b/gck/tests/test-gck-attributes.c
@@ -450,6 +450,8 @@ test_new_empty_attributes (void)
g_assert (attr->value == NULL);
g_assert (attr->length == 0);
}
+
+ gck_attributes_unref (attrs);
}
static void
diff --git a/gck/tests/test-gck-crypto.c b/gck/tests/test-gck-crypto.c
index 9630123..241b208 100644
--- a/gck/tests/test-gck-crypto.c
+++ b/gck/tests/test-gck-crypto.c
@@ -85,6 +85,10 @@ teardown (Test *test, gconstpointer unused)
g_object_unref (test->session);
g_object_unref (test->module);
g_object_unref (test->session_with_auth);
+
+ egg_assert_not_object (test->session);
+ egg_assert_not_object (test->session_with_auth);
+ egg_assert_not_object (test->module);
}
static void
@@ -102,6 +106,7 @@ find_key (GckSession *session, CK_ATTRIBUTE_TYPE method, CK_MECHANISM_TYPE mech)
GckAttributes *attrs;
GckObject *object = NULL;
CK_MECHANISM_TYPE_PTR mechs;
+ gboolean match;
gsize n_mechs;
attrs = gck_attributes_new ();
@@ -116,8 +121,12 @@ find_key (GckSession *session, CK_ATTRIBUTE_TYPE method, CK_MECHANISM_TYPE mech)
NULL, &n_mechs, NULL);
g_assert (mechs);
g_assert (n_mechs == sizeof (CK_MECHANISM_TYPE));
+
/* We know all of them only have one allowed mech */
- if (*mechs != mech)
+ match = (*mechs != mech);
+ g_free (mechs);
+
+ if (match)
continue;
}
object = l->data;
@@ -274,14 +283,16 @@ test_login_context_specific (Test *test, gconstpointer unused)
/* Find the right key */
key = find_key (test->session, CKA_SIGN, CKM_MOCK_PREFIX);
- g_assert (key);
+ g_assert (GCK_IS_OBJECT (key));
/* Simple one */
output = gck_session_sign (test->session, key, CKM_MOCK_PREFIX, (const guchar*)"TV Monster", 11, &n_output, NULL, &error);
g_assert_error (error, GCK_ERROR, CKR_USER_NOT_LOGGED_IN);
g_assert (output == NULL);
+ g_error_free (error);
g_object_unref (key);
+ egg_assert_not_object (key);
}
static void
@@ -341,7 +352,7 @@ test_verify (Test *test, gconstpointer unused)
/* Find the right key */
key = find_key (test->session, CKA_VERIFY, CKM_MOCK_PREFIX);
- g_assert (key);
+ g_assert (GCK_IS_OBJECT (key));
/* Simple one */
ret = gck_session_verify (test->session, key, CKM_MOCK_PREFIX, (const guchar*)"Labarbara", 10,
@@ -379,6 +390,7 @@ test_verify (Test *test, gconstpointer unused)
g_object_unref (result);
g_object_unref (key);
+ egg_assert_not_object (key);
}
static void
@@ -625,6 +637,13 @@ test_derive_key (Test *test, gconstpointer unused)
gck_attributes_unref (attrs);
}
+static void
+null_log_handler (const gchar *log_domain, GLogLevelFlags log_level,
+ const gchar *message, gpointer user_data)
+{
+
+}
+
int
main (int argc, char **argv)
{
@@ -633,6 +652,10 @@ main (int argc, char **argv)
g_set_prgname ("test-gck-crypto");
+ /* Suppress these messages in tests */
+ g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG,
+ null_log_handler, NULL);
+
g_test_add ("/gck/crypto/encrypt", Test, NULL, setup, test_encrypt, teardown);
g_test_add ("/gck/crypto/decrypt", Test, NULL, setup, test_decrypt, teardown);
g_test_add ("/gck/crypto/login_context_specific", Test, NULL, setup, test_login_context_specific, teardown);
@@ -643,5 +666,5 @@ main (int argc, char **argv)
g_test_add ("/gck/crypto/unwrap_key", Test, NULL, setup, test_unwrap_key, teardown);
g_test_add ("/gck/crypto/derive_key", Test, NULL, setup, test_derive_key, teardown);
- return egg_tests_run_in_thread_with_loop ();
+ return egg_tests_run_with_loop ();
}
diff --git a/gck/tests/test-gck-enumerator.c b/gck/tests/test-gck-enumerator.c
index b248b4e..f4f66ac 100644
--- a/gck/tests/test-gck-enumerator.c
+++ b/gck/tests/test-gck-enumerator.c
@@ -61,10 +61,11 @@ static void
teardown (Test *test, gconstpointer unused)
{
gck_list_unref_free (test->modules);
- test->modules = NULL;
g_object_unref (test->module);
- test->module = NULL;
+ egg_assert_not_object (test->module);
+
+ g_thread_pool_stop_unused_threads ();
}
static void
@@ -302,12 +303,17 @@ test_authenticate_interaction (Test *test,
g_object_get (en, "interaction", &check, NULL);
g_assert (interaction == check);
g_object_unref (interaction);
+ g_object_unref (check);
obj = gck_enumerator_next (en, NULL, &error);
g_assert (GCK_IS_OBJECT (obj));
g_object_unref (obj);
g_object_unref (en);
+
+ egg_assert_not_object (en);
+ egg_assert_not_object (obj);
+ egg_assert_not_object (interaction);
}
static gboolean
@@ -335,9 +341,10 @@ test_authenticate_compat (Test *test,
GError *error = NULL;
GckEnumerator *en;
GckObject *obj;
+ gulong sig;
- g_signal_connect (test->modules->data, "authenticate-slot",
- G_CALLBACK (on_authenticate_token), GUINT_TO_POINTER (35));
+ sig = g_signal_connect (test->modules->data, "authenticate-slot",
+ G_CALLBACK (on_authenticate_token), GUINT_TO_POINTER (35));
uri_data = gck_uri_data_new ();
en = _gck_enumerator_new_for_modules (test->modules, GCK_SESSION_LOGIN_USER, uri_data);
@@ -348,6 +355,11 @@ test_authenticate_compat (Test *test,
g_object_unref (obj);
g_object_unref (en);
+
+ g_signal_handler_disconnect (test->modules->data, sig);
+
+ egg_assert_not_object (obj);
+ egg_assert_not_object (en);
}
static void
@@ -561,5 +573,5 @@ main (int argc, char **argv)
g_test_add ("/gck/enumerator/attribute_get", Test, NULL, setup, test_attribute_get, teardown);
g_test_add ("/gck/enumerator/chained", Test, NULL, setup, test_chained, teardown);
- return egg_tests_run_in_thread_with_loop ();
+ return egg_tests_run_with_loop ();
}
diff --git a/gck/tests/test-gck-module.c b/gck/tests/test-gck-module.c
index b5db530..2a1d3a1 100644
--- a/gck/tests/test-gck-module.c
+++ b/gck/tests/test-gck-module.c
@@ -51,6 +51,7 @@ static void
teardown (Test *test, gconstpointer unused)
{
g_object_unref (test->module);
+ egg_assert_not_object (test->module);
}
static void
@@ -172,5 +173,5 @@ main (int argc, char **argv)
g_test_add ("/gck/module/module_props", Test, NULL, setup, test_module_props, teardown);
g_test_add ("/gck/module/module_info", Test, NULL, setup, test_module_info, teardown);
- return egg_tests_run_in_thread_with_loop ();
+ return egg_tests_run_with_loop ();
}
diff --git a/gck/tests/test-gck-modules.c b/gck/tests/test-gck-modules.c
index 246c771..0c3494e 100644
--- a/gck/tests/test-gck-modules.c
+++ b/gck/tests/test-gck-modules.c
@@ -206,5 +206,5 @@ main (int argc, char **argv)
g_test_add ("/gck/modules/objects_for_uri", Test, NULL, setup, test_objects_for_uri, teardown);
g_test_add ("/gck/modules/enumerate_uri", Test, NULL, setup, test_enumerate_uri, teardown);
- return egg_tests_run_in_thread_with_loop ();
+ return egg_tests_run_with_loop ();
}
diff --git a/gck/tests/test-gck-object.c b/gck/tests/test-gck-object.c
index f102620..43db29a 100644
--- a/gck/tests/test-gck-object.c
+++ b/gck/tests/test-gck-object.c
@@ -216,6 +216,8 @@ test_destroy_object (Test *test, gconstpointer unused)
g_assert_no_error (err);
g_assert (ret);
g_object_unref (object);
+
+ gck_attributes_unref (attrs);
}
static void
@@ -335,6 +337,7 @@ test_set_attributes (Test *test, gconstpointer unused)
/* Async */
gck_object_set_async (test->object, templ, NULL, fetch_async_result, &result);
+ gck_attributes_unref (templ);
egg_test_wait_until (500);
g_assert (result != NULL);
@@ -398,6 +401,7 @@ test_find_objects (Test *test, gconstpointer unused)
g_object_unref (result);
g_assert (objects == NULL);
gck_list_unref_free (objects);
+ gck_attributes_unref (templ);
}
int
@@ -415,5 +419,5 @@ main (int argc, char **argv)
g_test_add ("/gck/object/set_attributes", Test, NULL, setup, test_set_attributes, teardown);
g_test_add ("/gck/object/find_objects", Test, NULL, setup, test_find_objects, teardown);
- return egg_tests_run_in_thread_with_loop ();
+ return egg_tests_run_with_loop ();
}
diff --git a/gck/tests/test-gck-session.c b/gck/tests/test-gck-session.c
index 24323ff..8e88422 100644
--- a/gck/tests/test-gck-session.c
+++ b/gck/tests/test-gck-session.c
@@ -72,7 +72,10 @@ 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));
+
+ egg_assert_not_object (test->session);
+ egg_assert_not_object (test->slot);
+ egg_assert_not_object (test->module);
}
static void
@@ -139,10 +142,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));
+ egg_assert_not_object (result);
g_object_unref (sess);
- g_assert (!G_IS_OBJECT (sess));
+ egg_assert_not_object (sess);
}
static void
@@ -486,6 +489,7 @@ test_auto_login (Test *test, gconstpointer unused)
g_assert_no_error (err);
g_assert (ret);
+ gck_attributes_unref (attrs);
g_object_unref (new_session);
}
@@ -508,5 +512,5 @@ main (int argc, char **argv)
g_test_add ("/gck/session/login_interactive", Test, NULL, setup, test_login_interactive, teardown);
g_test_add ("/gck/session/auto_login", Test, NULL, setup, test_auto_login, teardown);
- return egg_tests_run_in_thread_with_loop ();
+ return egg_tests_run_with_loop ();
}
diff --git a/gck/tests/test-gck-slot.c b/gck/tests/test-gck-slot.c
index affc3b2..3048026 100644
--- a/gck/tests/test-gck-slot.c
+++ b/gck/tests/test-gck-slot.c
@@ -156,7 +156,7 @@ test_slot_equals_hash (Test *test, gconstpointer unused)
g_object_unref (obj);
other_slot = g_object_new (GCK_TYPE_SLOT, "module", test->module, "handle", 8909, NULL);
- g_assert (!gck_slot_equal (test->slot, obj));
+ g_assert (!gck_slot_equal (test->slot, other_slot));
g_object_unref (other_slot);
}
diff --git a/gck/tests/test-gck-uri.c b/gck/tests/test-gck-uri.c
index b8d640f..b42cc6c 100644
--- a/gck/tests/test-gck-uri.c
+++ b/gck/tests/test-gck-uri.c
@@ -340,6 +340,7 @@ test_build_with_attributes (void)
if (!gck_attributes_find_string (check->attributes, CKA_LABEL, &string))
g_assert_not_reached ();
g_assert_cmpstr (string, ==, "The Label");
+ g_free (string);
if (!gck_attributes_find_ulong (check->attributes, CKA_CLASS, &value))
g_assert_not_reached ();