Make sure bs is assigned NULL when it's free'd, or there will be an
[openssl.git] / crypto / asn1 / d2i_r_pr.c
index f6d118937cbdb0133c468d7f66b91c4c0813d445..46037a04e639b2c950735620137396f1152fa348 100644 (file)
@@ -56,6 +56,7 @@
  * [including the GNU Public Licence.]
  */
 
+#ifndef NO_RSA
 #include <stdio.h>
 #include "cryptlib.h"
 #include <openssl/bn.h>
@@ -74,7 +75,7 @@ ASN1_METHOD *RSAPrivateKey_asn1_meth(void)
        return(&method);
        }
 
-RSA *d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length)
+RSA *d2i_RSAPrivateKey(RSA **a, const unsigned char **pp, long length)
        {
        int i=ASN1_R_PARSING;
        ASN1_INTEGER *bs=NULL;
@@ -106,7 +107,8 @@ RSA *d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length)
        if ((ret->iqmp=BN_bin2bn(bs->data,bs->length,ret->iqmp)) == NULL)
                goto err_bn;
 
-       ASN1_INTEGER_free(bs);
+       M_ASN1_INTEGER_free(bs);
+       bs = NULL;
 
        M_ASN1_D2I_Finish_2(a);
 err_bn:
@@ -114,7 +116,14 @@ err_bn:
 err:
        ASN1err(ASN1_F_D2I_RSAPRIVATEKEY,i);
        if ((ret != NULL) && ((a == NULL) || (*a != ret))) RSA_free(ret);
-       if (bs != NULL) ASN1_INTEGER_free(bs);
+       if (bs != NULL) M_ASN1_INTEGER_free(bs);
+
        return(NULL);
        }
+#else /* !NO_RSA */
+
+# if PEDANTIC
+static void *dummy=&dummy;
+# endif
 
+#endif