Fix memory leak in pkcs12 -export
authorDmitry Belyavskiy <beldmit@gmail.com>
Sat, 18 Feb 2017 17:43:01 +0000 (20:43 +0300)
committerRich Salz <rsalz@openssl.org>
Tue, 21 Feb 2017 20:00:18 +0000 (15:00 -0500)
Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/2676)
(cherry picked from commit 1b8f19379a521ec11ce37e12316dd3edc0acfb82)

crypto/pkcs12/p12_mutl.c

index cbf34da05adadb6790d35b7f578b51e4a8680692..b1f7381a6fb5e400d438988136ede0dc03d93b69 100644 (file)
@@ -159,7 +159,10 @@ int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen,
 int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, int saltlen,
                      const EVP_MD *md_type)
 {
-    if (!(p12->mac = PKCS12_MAC_DATA_new()))
+    PKCS12_MAC_DATA_free(p12->mac);
+    p12->mac = NULL;
+
+    if ((p12->mac = PKCS12_MAC_DATA_new()) == NULL)
         return PKCS12_ERROR;
     if (iter > 1) {
         if (!(p12->mac->iter = M_ASN1_INTEGER_new())) {