summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stefw@collabora.co.uk>2011-06-07 12:44:06 +0000
committerStef Walter <stefw@collabora.co.uk>2011-06-07 12:44:06 +0000
commitb315f99c90d01104d6baa91ca0f2cfb32c920abd (patch)
tree9d714ed7f0d70ee82a2998a070a1b9fed521c269
parent7f5d2e9471872d8c1cf7181ba647c1dc74e2c6dd (diff)
downloadp11-kit-b315f99c90d01104d6baa91ca0f2cfb32c920abd.tar.gz
Fix more memory errors and leaks in module code.
-rw-r--r--p11-kit/modules.c16
-rw-r--r--tools/p11-kit.c3
2 files changed, 15 insertions, 4 deletions
diff --git a/p11-kit/modules.c b/p11-kit/modules.c
index e2cecd9..2df801f 100644
--- a/p11-kit/modules.c
+++ b/p11-kit/modules.c
@@ -170,7 +170,7 @@ strconcat (const char *first, ...)
va_end (va);
- at = result = malloc (length);
+ at = result = malloc (length + 1);
if (!result)
return NULL;
@@ -471,7 +471,8 @@ load_modules_from_config_unlocked (const char *directory)
dir = opendir (directory);
if (!dir) {
if (errno == ENOENT || errno == ENOTDIR)
- warning ("couldn't list directory: %s", directory);
+ return CKR_OK;
+ warning ("couldn't list directory: %s", directory);
return CKR_GENERAL_ERROR;
}
@@ -858,8 +859,10 @@ _p11_kit_initialize_registered_unlocked_reentrant (void)
CK_RV rv;
rv = init_globals_unlocked ();
- if (rv == CKR_OK)
- rv = load_registered_modules_unlocked ();
+ if (rv != CKR_OK)
+ return rv;
+
+ rv = load_registered_modules_unlocked ();
if (rv == CKR_OK) {
hash_iterate (gl.modules, &it);
while (hash_next (&it, NULL, (void**)&mod)) {
@@ -952,6 +955,11 @@ _p11_kit_finalize_registered_unlocked_reentrant (void)
}
free (to_finalize);
+
+ /* In case nothing loaded, free up internal memory */
+ if (count == 0)
+ free_modules_when_no_refs_unlocked ();
+
return CKR_OK;
}
diff --git a/tools/p11-kit.c b/tools/p11-kit.c
index 7e84416..175b561 100644
--- a/tools/p11-kit.c
+++ b/tools/p11-kit.c
@@ -83,6 +83,9 @@ list_modules (int argc, char *argv[])
free (name);
free (path);
}
+ free (module_list);
+
+ p11_kit_finalize_registered ();
return 0;
}