Commit 818bbcf475 for openssl.org

commit 818bbcf4751fab2b87045156afb59c8e9f53f499
Author: Alexandr Nedvedicky <sashan@openssl.org>
Date:   Mon Jan 5 13:18:46 2026 +0100

    ctx_simd and ctx_ref must be freed in error path

    CID 1679597
    CID 1679599

    Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
    Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
    Reviewed-by: Paul Dale <paul.dale@oracle.com>
    Reviewed-by: Norbert Pocs <norbertp@openssl.org>
    MergeDate: Thu Jan  8 10:10:49 2026
    (Merged from https://github.com/openssl/openssl/pull/29543)

diff --git a/test/test_base64_simdutf.c b/test/test_base64_simdutf.c
index 29932eea60..e6026c4f38 100644
--- a/test/test_base64_simdutf.c
+++ b/test/test_base64_simdutf.c
@@ -161,6 +161,8 @@ static int test_encode_line_lengths_reinforced(void)
     /* Generous output buffers (Update + Final + newlines), plus a guard byte */
     unsigned char out_simd[9000 * 2 + 1] = { 0 };
     unsigned char out_ref[9000 * 2 + 1] = { 0 };
+    EVP_ENCODE_CTX *ctx_simd = NULL;
+    EVP_ENCODE_CTX *ctx_ref = NULL;

     for (int t = 0; t < trials; t++) {
         uint32_t r = next_u32(&seed);
@@ -174,14 +176,12 @@ static int test_encode_line_lengths_reinforced(void)
         for (int partial_ctx_fill = 0; partial_ctx_fill <= 80;
             partial_ctx_fill += 1) {
             for (int ctx_len = 1; ctx_len <= 80; ctx_len += 1) {
-                EVP_ENCODE_CTX *ctx_simd = EVP_ENCODE_CTX_new();
-                EVP_ENCODE_CTX *ctx_ref = EVP_ENCODE_CTX_new();
+                ctx_simd = EVP_ENCODE_CTX_new();
+                ctx_ref = EVP_ENCODE_CTX_new();

                 if (!ctx_simd || !ctx_ref) {
-                    EVP_ENCODE_CTX_free(ctx_simd);
-                    EVP_ENCODE_CTX_free(ctx_ref);
                     TEST_error("Out of memory for contexts");
-                    return 0;
+                    goto fail;
                 }

                 fuzz_fill_encode_ctx(ctx_simd, partial_ctx_fill);
@@ -216,7 +216,7 @@ static int test_encode_line_lengths_reinforced(void)
                     if (!TEST_int_eq(ret_simd, ret_ref)
                         || !TEST_mem_eq(out_ref, outlen_ref, out_simd, outlen_simd)
                         || !TEST_int_eq(outlen_simd, outlen_ref))
-                        return 0;
+                        goto fail;

                     EVP_EncodeFinal(ctx_simd, out_simd + outlen_simd,
                         &finlen_simd);
@@ -228,7 +228,7 @@ static int test_encode_line_lengths_reinforced(void)

                     if (!TEST_int_eq(finlen_simd, finlen_ref)
                         || !TEST_mem_eq(out_ref, total_ref, out_simd, total_simd))
-                        return 0;
+                        goto fail;
                 }

                 EVP_ENCODE_CTX_free(ctx_simd);
@@ -238,6 +238,11 @@ static int test_encode_line_lengths_reinforced(void)
     }

     return 1;
+
+fail:
+    EVP_ENCODE_CTX_free(ctx_simd);
+    EVP_ENCODE_CTX_free(ctx_ref);
+    return 0;
 }

 int setup_tests(void)