Fix a memory leak in PKCS12_parse.
[openssl.git] / crypto / asn1 / x_pubkey.c
index 857b7c885865868349e6bd9a07fba9955ee4696d..7a05d575c992da5f7ec1ead114ae31eac4d9af91 100644 (file)
@@ -112,7 +112,7 @@ void X509_PUBKEY_free(X509_PUBKEY *a)
        X509_ALGOR_free(a->algor);
        M_ASN1_BIT_STRING_free(a->public_key);
        if (a->pkey != NULL) EVP_PKEY_free(a->pkey);
-       Free((char *)a);
+       Free(a);
        }
 
 int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
@@ -183,8 +183,10 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
 
        Free(s);
 
+#if 0
        CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
        pk->pkey=pkey;
+#endif
 
        if (*x != NULL)
                X509_PUBKEY_free(*x);
@@ -297,7 +299,7 @@ RSA *d2i_RSA_PUBKEY(RSA **a, unsigned char **pp,
        q = *pp;
        pkey = d2i_PUBKEY(NULL, &q, length);
        if(!pkey) return NULL;
-       key = EVP_PKEY_rget_RSA(pkey);
+       key = EVP_PKEY_get1_RSA(pkey);
        EVP_PKEY_free(pkey);
        if(!key) return NULL;
        *pp = q;
@@ -318,7 +320,7 @@ int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp)
                ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE);
                return 0;
        }
-       EVP_PKEY_rset_RSA(pktmp, a);
+       EVP_PKEY_set1_RSA(pktmp, a);
        ret = i2d_PUBKEY(pktmp, pp);
        EVP_PKEY_free(pktmp);
        return ret;
@@ -335,7 +337,7 @@ DSA *d2i_DSA_PUBKEY(DSA **a, unsigned char **pp,
        q = *pp;
        pkey = d2i_PUBKEY(NULL, &q, length);
        if(!pkey) return NULL;
-       key = EVP_PKEY_rget_DSA(pkey);
+       key = EVP_PKEY_get1_DSA(pkey);
        EVP_PKEY_free(pkey);
        if(!key) return NULL;
        *pp = q;
@@ -356,7 +358,7 @@ int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp)
                ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE);
                return 0;
        }
-       EVP_PKEY_rset_DSA(pktmp, a);
+       EVP_PKEY_set1_DSA(pktmp, a);
        ret = i2d_PUBKEY(pktmp, pp);
        EVP_PKEY_free(pktmp);
        return ret;