]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
ctx_simd and ctx_ref must be freed in error path
authorAlexandr Nedvedicky <sashan@openssl.org>
Mon, 5 Jan 2026 12:18:46 +0000 (13:18 +0100)
committerTomas Mraz <tomas@openssl.org>
Thu, 8 Jan 2026 10:10:46 +0000 (11:10 +0100)
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)

test/test_base64_simdutf.c

index 29932eea6032a9d3dff1d55b0045502a16df3943..e6026c4f38c55e2cb951b8f0a0ab1191731ce1ed 100644 (file)
@@ -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)