Fix Coverity issues
[openssl.git] / providers / default / ciphers / cipher_aes_ocb.c
index 8875d79a87baf14159c94776ed16e03a69351b58..93df4a5dbc75542b9b5d5df47316a07e476c4e76 100644 (file)
@@ -285,9 +285,11 @@ static void aes_ocb_freectx(void *vctx)
 {
     PROV_AES_OCB_CTX *ctx = (PROV_AES_OCB_CTX *)vctx;
 
-    aes_generic_ocb_cleanup(ctx);
-    OPENSSL_cleanse(ctx->base.iv, sizeof(ctx->base.iv));
-    OPENSSL_clear_free(ctx,  sizeof(*ctx));
+    if (ctx != NULL) {
+        aes_generic_ocb_cleanup(ctx);
+        OPENSSL_cleanse(ctx->base.iv, sizeof(ctx->base.iv));
+        OPENSSL_clear_free(ctx,  sizeof(*ctx));
+    }
 }
 
 static void *aes_ocb_dupctx(void *vctx)
@@ -300,8 +302,10 @@ static void *aes_ocb_dupctx(void *vctx)
         return NULL;
     }
     *ret = *in;
-    if (!aes_generic_ocb_copy_ctx(ret, in))
+    if (!aes_generic_ocb_copy_ctx(ret, in)) {
         OPENSSL_free(ret);
+        ret = NULL;
+    }
     return ret;
 }