From b315f99c90d01104d6baa91ca0f2cfb32c920abd Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Tue, 7 Jun 2011 12:44:06 +0000 Subject: Fix more memory errors and leaks in module code. --- p11-kit/modules.c | 16 ++++++++++++---- tools/p11-kit.c | 3 +++ 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; } -- cgit v1.1