Avoid potential memory leak
authorDmitry Belyavskiy <beldmit@gmail.com>
Mon, 7 Mar 2022 16:05:57 +0000 (17:05 +0100)
committerMatt Caswell <matt@openssl.org>
Thu, 10 Mar 2022 14:12:15 +0000 (14:12 +0000)
Resolves #17827

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17828)

(cherry picked from commit 175355923046921a689b500f7a72455f7095708f)

crypto/x509/v3_utl.c

index 09fed073988691c836e7018792789c979c57fb10..633cd2679f7de884c69b647eb743dffc06843013 100644 (file)
@@ -539,8 +539,11 @@ static int append_ia5(STACK_OF(OPENSSL_STRING) **sk,
         return 0;
 
     emtmp = OPENSSL_strndup((char *)email->data, email->length);
-    if (emtmp == NULL)
+    if (emtmp == NULL) {
+        X509_email_free(*sk);
+        *sk = NULL;
         return 0;
+    }
 
     /* Don't add duplicates */
     if (sk_OPENSSL_STRING_find(*sk, emtmp) != -1) {