Free DRBG context in self tests.
authorDr. Stephen Henson <steve@openssl.org>
Mon, 21 Mar 2011 14:40:57 +0000 (14:40 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Mon, 21 Mar 2011 14:40:57 +0000 (14:40 +0000)
fips/rand/fips_drbg_lib.c
fips/rand/fips_drbg_selftest.c

index 94bc36a31f52f30a49e38254c0bd034faa967108..a015da1e41cf5c26fa81aaccd84ca358942d75be 100644 (file)
@@ -112,7 +112,8 @@ DRBG_CTX *FIPS_drbg_new(int type, unsigned int flags)
 
 void FIPS_drbg_free(DRBG_CTX *dctx)
        {
-       dctx->uninstantiate(dctx);
+       if (dctx->uninstantiate)
+               dctx->uninstantiate(dctx);
        OPENSSL_cleanse(dctx, sizeof(DRBG_CTX));
        OPENSSL_free(dctx);
        }
@@ -388,8 +389,9 @@ int FIPS_drbg_uninstantiate(DRBG_CTX *dctx)
        {
        int rv;
        if (!dctx->uninstantiate)
-               return 1;
-       rv = dctx->uninstantiate(dctx);
+               rv = 1;
+       else
+               rv = dctx->uninstantiate(dctx);
        /* Although we'd like to cleanse here we can't because we have to
         * test the uninstantiate really zeroes the data.
         */
index f580eafb4ae9e0f86ff8ef4e2988509ea2ab9f5b..af21971ba0a2a7ffc2563ae17390295ce5132d8c 100644 (file)
@@ -1011,6 +1011,7 @@ int FIPS_selftest_drbg(void)
                if (!fips_drbg_health_check(dctx, td))
                        break;
                }
+       FIPS_drbg_free(dctx);
        if (td->nid == 0)
                return 1;
        return 0;