From: JiashengJiang Date: Mon, 5 May 2025 17:46:53 +0000 (-0400) Subject: crypto/x509/v3_lib.c: Free tmpext if X509V3_EXT_add() fails to avoid memory leak X-Git-Tag: openssl-3.4.2~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=251d2851ce5cce95c6620fa6490c0d25444d7eeb;p=thirdparty%2Fopenssl.git crypto/x509/v3_lib.c: Free tmpext if X509V3_EXT_add() fails to avoid memory leak Add OPENSSL_free to free tmpext if X509V3_EXT_add() fails to avoid memory leak. Fixes: 878dc8dd95 ("Join the x509 and x509v3 directories") Signed-off-by: JiashengJiang Reviewed-by: Tom Cosgrove Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/27566) (cherry picked from commit 5f661e4e96bc3bfa52b4e0735f407cb41f162869) --- diff --git a/crypto/x509/v3_lib.c b/crypto/x509/v3_lib.c index 077b22c863e..ad9faf5bfe3 100644 --- a/crypto/x509/v3_lib.c +++ b/crypto/x509/v3_lib.c @@ -100,7 +100,11 @@ int X509V3_EXT_add_alias(int nid_to, int nid_from) *tmpext = *ext; tmpext->ext_nid = nid_to; tmpext->ext_flags |= X509V3_EXT_DYNAMIC; - return X509V3_EXT_add(tmpext); + if (!X509V3_EXT_add(tmpext)) { + OPENSSL_free(tmpext); + return 0; + } + return 1; } void X509V3_EXT_cleanup(void)