]> granicus.if.org Git - p11-kit/commitdiff
Fix more memory errors and leaks in module code.
authorStef Walter <stefw@collabora.co.uk>
Tue, 7 Jun 2011 12:44:06 +0000 (12:44 +0000)
committerStef Walter <stefw@collabora.co.uk>
Tue, 7 Jun 2011 12:44:06 +0000 (12:44 +0000)
p11-kit/modules.c
tools/p11-kit.c

index e2cecd99d19647a3ba46ecbc715ce919fc77dea4..2df801ffb88e56794984e1afefddb68ae7831667 100644 (file)
@@ -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;
 }
 
index 7e8441633e2a442753e38bcb319d1b16768db00b..175b561fae98967ad03a0f5500571ab0c35181ef 100644 (file)
@@ -83,6 +83,9 @@ list_modules (int argc, char *argv[])
                free (name);
                free (path);
        }
+       free (module_list);
+
+       p11_kit_finalize_registered ();
 
        return 0;
 }