Commit 13015c3f41 for openssl.org

commit 13015c3f41ba33a6b247ee564dde0586043e7e4a
Author: Nikola Pajkovsky <nikolap@openssl.org>
Date:   Fri Dec 5 11:00:22 2025 +0100

    key2any: free val if string is empty

    Resolves: https://scan5.scan.coverity.com/#/project-view/65138/10222?selectedIssue=1675327
    Signed-off-by: Nikola Pajkovsky <nikolap@openssl.org>

    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
    Reviewed-by: Tim Hudson <tjh@openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/29317)

diff --git a/providers/implementations/encode_decode/encode_key2any.c b/providers/implementations/encode_decode/encode_key2any.c
index c9a718694d..6122627d69 100644
--- a/providers/implementations/encode_decode/encode_key2any.c
+++ b/providers/implementations/encode_decode/encode_key2any.c
@@ -1181,7 +1181,12 @@ static int key2any_set_ctx_params(void *vctx, const OSSL_PARAM params[])
         if (!OSSL_PARAM_get_utf8_string(p.output_formats, &val, 0))
             return 0;
         OPENSSL_free(ctx->output_formats);
-        ctx->output_formats = *val != '\0' ? val : NULL;
+        if (*val != '\0') {
+            ctx->output_formats = val;
+        } else {
+            OPENSSL_free(val);
+            ctx->output_formats = NULL;
+        }
     }

     return 1;