kdfs: make free calls check for NULL.
[openssl.git] / providers / implementations / kdfs / scrypt.c
index 505963eec51cc187b07d77d8f9ecd40c93a01219..425db1af6f2907e7c1b3669332f7248b6ee74eac 100644 (file)
 #include <openssl/core_names.h>
 #include "crypto/evp.h"
 #include "internal/numbers.h"
-#include "internal/provider_algs.h"
-#include "internal/provider_ctx.h"
-#include "internal/providercommonerr.h"
-#include "internal/provider_algs.h"
+#include "prov/implementations.h"
+#include "prov/provider_ctx.h"
+#include "prov/providercommonerr.h"
+#include "prov/implementations.h"
 
 #ifndef OPENSSL_NO_SCRYPT
 
@@ -74,9 +74,11 @@ static void kdf_scrypt_free(void *vctx)
 {
     KDF_SCRYPT *ctx = (KDF_SCRYPT *)vctx;
 
-    EVP_MD_meth_free(ctx->sha256);
-    kdf_scrypt_reset(ctx);
-    OPENSSL_free(ctx);
+    if (ctx != NULL) {
+        EVP_MD_meth_free(ctx->sha256);
+        kdf_scrypt_reset(ctx);
+        OPENSSL_free(ctx);
+    }
 }
 
 static void kdf_scrypt_reset(void *vctx)