Commit 2f4ef4a912 for openssl.org

commit 2f4ef4a912f2fd0548ebb46d2c274a908acd0a72
Author: Eugene Syromiatnikov <esyr@openssl.org>
Date:   Mon Feb 23 06:39:29 2026 +0100

    test/ech_corrupt_test.c: avoid memory leak in tls_corrupt_write()

    corrupt_or_copy() may return 0 while still setting returning the allocated
    memory in copy, avoid leaking it by always calling OPENSSL_free() on it.

    Resolves: https://scan5.scan.coverity.com/#/project-view/65248/10222?selectedIssue=1681460
    Fixes: 5e5a76fc2c08 "Add tests and documentation and fix a couple of issues identified by added tests"
    Signed-off-by: Eugene Syromiatnikov <esyr@openssl.org>

    Reviewed-by: Matt Caswell <matt@openssl.org>
    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    MergeDate: Wed Feb 25 11:10:57 2026
    (Merged from https://github.com/openssl/openssl/pull/30139)

diff --git a/test/ech_corrupt_test.c b/test/ech_corrupt_test.c
index 2c68d49c4c..28b681ed08 100644
--- a/test/ech_corrupt_test.c
+++ b/test/ech_corrupt_test.c
@@ -1282,10 +1282,11 @@ static int tls_corrupt_write(BIO *bio, const char *in, int inl)

     ret = corrupt_or_copy(in, inl, &copy, &copylen);
     if (ret == 0)
-        return 0;
+        goto out;
     ret = BIO_write(next, copy, inl);
-    OPENSSL_free(copy);
     copy_flags(bio);
+out:
+    OPENSSL_free(copy);
     return ret;
 }