Fix mem leak on error path
authorMatt Caswell <matt@openssl.org>
Mon, 22 Aug 2016 22:23:31 +0000 (23:23 +0100)
committerMatt Caswell <matt@openssl.org>
Mon, 22 Aug 2016 23:19:15 +0000 (00:19 +0100)
The mem pointed to by cAB can be leaked on an error path.

Reviewed-by: Tim Hudson <tjh@openssl.org>
crypto/srp/srp_lib.c

index f146f820e7fa7edd179ec2663a6b2d5e11c2fd03..ddd86b7517641ff4b034c54fd9ce035df239375b 100644 (file)
@@ -168,7 +168,7 @@ BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass)
 {
     unsigned char dig[SHA_DIGEST_LENGTH];
     EVP_MD_CTX *ctxt;
-    unsigned char *cs;
+    unsigned char *cs = NULL;
     BIGNUM *res = NULL;
 
     if ((s == NULL) || (user == NULL) || (pass == NULL))
@@ -190,13 +190,15 @@ BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass)
     BN_bn2bin(s, cs);
     if (!EVP_DigestUpdate(ctxt, cs, BN_num_bytes(s)))
         goto err;
-    OPENSSL_free(cs);
+
     if (!EVP_DigestUpdate(ctxt, dig, sizeof(dig))
         || !EVP_DigestFinal_ex(ctxt, dig, NULL))
         goto err;
 
     res = BN_bin2bn(dig, sizeof(dig), NULL);
+
  err:
+    OPENSSL_free(cs);
     EVP_MD_CTX_free(ctxt);
     return res;
 }