free NULL cleanup

Start ensuring all OpenSSL "free" routines allow NULL, and remove
any if check before calling them.
This gets DH_free, DSA_free, RSA_free

Reviewed-by: Matt Caswell <matt@openssl.org>
This commit is contained in:
Rich Salz
2015-03-24 10:17:37 -04:00
parent 1300705a47
commit d64070838e
34 changed files with 58 additions and 108 deletions

View File

@@ -3138,8 +3138,7 @@ void ssl3_free(SSL *s)
if (s->s3->rrec.comp != NULL)
OPENSSL_free(s->s3->rrec.comp);
#ifndef OPENSSL_NO_DH
if (s->s3->tmp.dh != NULL)
DH_free(s->s3->tmp.dh);
DH_free(s->s3->tmp.dh);
#endif
#ifndef OPENSSL_NO_EC
if (s->s3->tmp.ecdh != NULL)
@@ -3181,10 +3180,8 @@ void ssl3_clear(SSL *s)
s->s3->rrec.comp = NULL;
}
#ifndef OPENSSL_NO_DH
if (s->s3->tmp.dh != NULL) {
DH_free(s->s3->tmp.dh);
s->s3->tmp.dh = NULL;
}
DH_free(s->s3->tmp.dh);
s->s3->tmp.dh = NULL;
#endif
#ifndef OPENSSL_NO_EC
if (s->s3->tmp.ecdh != NULL) {
@@ -3293,8 +3290,7 @@ long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg)
SSLerr(SSL_F_SSL3_CTRL, ERR_R_RSA_LIB);
return (ret);
}
if (s->cert->rsa_tmp != NULL)
RSA_free(s->cert->rsa_tmp);
RSA_free(s->cert->rsa_tmp);
s->cert->rsa_tmp = rsa;
ret = 1;
}
@@ -3329,8 +3325,7 @@ long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg)
return (ret);
}
}
if (s->cert->dh_tmp != NULL)
DH_free(s->cert->dh_tmp);
DH_free(s->cert->dh_tmp);
s->cert->dh_tmp = dh;
ret = 1;
}
@@ -3766,8 +3761,7 @@ long ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg)
SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_RSA_LIB);
return (0);
} else {
if (cert->rsa_tmp != NULL)
RSA_free(cert->rsa_tmp);
RSA_free(cert->rsa_tmp);
cert->rsa_tmp = rsa;
return (1);
}
@@ -3801,8 +3795,7 @@ long ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg)
return 0;
}
}
if (cert->dh_tmp != NULL)
DH_free(cert->dh_tmp);
DH_free(cert->dh_tmp);
cert->dh_tmp = new;
return 1;
}