Fix memory leak on error.
authorDr. Stephen Henson <steve@openssl.org>
Thu, 8 Sep 2016 14:10:32 +0000 (15:10 +0100)
committerDr. Stephen Henson <steve@openssl.org>
Sun, 11 Sep 2016 22:52:34 +0000 (23:52 +0100)
Backport leak fix from master branch.

Thanks to Shi Lei for reporting this bug.

Reviewed-by: Rich Salz <rsalz@openssl.org>
crypto/x509/x509spki.c

index 2df84ead9ef90e0cee7a894c928486cd34a19ba3..5ae5d30a35160a2e77146420dd0d25f46d303264 100644 (file)
@@ -112,6 +112,8 @@ char *NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki)
     der_spki = OPENSSL_malloc(der_len);
     b64_str = OPENSSL_malloc(der_len * 2);
     if (!der_spki || !b64_str) {
+        OPENSSL_free(der_spki);
+        OPENSSL_free(b64_str);
         X509err(X509_F_NETSCAPE_SPKI_B64_ENCODE, ERR_R_MALLOC_FAILURE);
         return NULL;
     }