Skip to content

Commit f419e23

Browse files
author
Andras Fekete
committed
Remove NULL test with 'ptr = NULL' at the end
1 parent d350ba6 commit f419e23

25 files changed

Lines changed: 194 additions & 392 deletions

src/dtls.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,10 +1340,8 @@ int wolfSSL_dtls_cid_set(WOLFSSL* ssl, unsigned char* cid, unsigned int size)
13401340
if (cidInfo == NULL)
13411341
return WOLFSSL_FAILURE;
13421342

1343-
if (cidInfo->rx != NULL) {
1344-
XFREE(cidInfo->rx, ssl->heap, DYNAMIC_TYPE_TLSX);
1345-
cidInfo->rx = NULL;
1346-
}
1343+
XFREE(cidInfo->rx, ssl->heap, DYNAMIC_TYPE_TLSX);
1344+
cidInfo->rx = NULL;
13471345

13481346
/* empty CID */
13491347
if (size == 0)

src/internal.c

Lines changed: 32 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,10 +2623,8 @@ void SSL_CtxResourceFree(WOLFSSL_CTX* ctx)
26232623
XFREE(ctx->method, heapAtCTXInit, DYNAMIC_TYPE_METHOD);
26242624
ctx->method = NULL;
26252625

2626-
if (ctx->suites) {
2627-
XFREE(ctx->suites, ctx->heap, DYNAMIC_TYPE_SUITES);
2628-
ctx->suites = NULL;
2629-
}
2626+
XFREE(ctx->suites, ctx->heap, DYNAMIC_TYPE_SUITES);
2627+
ctx->suites = NULL;
26302628

26312629
#ifndef NO_DH
26322630
XFREE(ctx->serverDH_G.buffer, ctx->heap, DYNAMIC_TYPE_PUBLIC_KEY);
@@ -2725,10 +2723,8 @@ void SSL_CtxResourceFree(WOLFSSL_CTX* ctx)
27252723
XFREE((void*)ctx->alpn_cli_protos, ctx->heap, DYNAMIC_TYPE_OPENSSL);
27262724
ctx->alpn_cli_protos = NULL;
27272725
}
2728-
if (ctx->param) {
2729-
XFREE(ctx->param, heapAtCTXInit, DYNAMIC_TYPE_OPENSSL);
2730-
ctx->param = NULL;
2731-
}
2726+
XFREE(ctx->param, heapAtCTXInit, DYNAMIC_TYPE_OPENSSL);
2727+
ctx->param = NULL;
27322728

27332729
if (ctx->x509_store.param) {
27342730
XFREE(ctx->x509_store.param, heapAtCTXInit, DYNAMIC_TYPE_OPENSSL);
@@ -4572,18 +4568,12 @@ void FreeX509(WOLFSSL_X509* x509)
45724568
x509->authKeyId = NULL;
45734569
XFREE(x509->subjKeyId, x509->heap, DYNAMIC_TYPE_X509_EXT);
45744570
x509->subjKeyId = NULL;
4575-
if (x509->authInfo != NULL) {
4576-
XFREE(x509->authInfo, x509->heap, DYNAMIC_TYPE_X509_EXT);
4577-
x509->authInfo = NULL;
4578-
}
4579-
if (x509->rawCRLInfo != NULL) {
4580-
XFREE(x509->rawCRLInfo, x509->heap, DYNAMIC_TYPE_X509_EXT);
4581-
x509->rawCRLInfo = NULL;
4582-
}
4583-
if (x509->CRLInfo != NULL) {
4584-
XFREE(x509->CRLInfo, x509->heap, DYNAMIC_TYPE_X509_EXT);
4585-
x509->CRLInfo = NULL;
4586-
}
4571+
XFREE(x509->authInfo, x509->heap, DYNAMIC_TYPE_X509_EXT);
4572+
x509->authInfo = NULL;
4573+
XFREE(x509->rawCRLInfo, x509->heap, DYNAMIC_TYPE_X509_EXT);
4574+
x509->rawCRLInfo = NULL;
4575+
XFREE(x509->CRLInfo, x509->heap, DYNAMIC_TYPE_X509_EXT);
4576+
x509->CRLInfo = NULL;
45874577
#if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || \
45884578
defined(WOLFSSL_QT)
45894579
XFREE(x509->authInfoCaIssuer, x509->heap, DYNAMIC_TYPE_X509_EXT);
@@ -4642,14 +4632,10 @@ void FreeX509(WOLFSSL_X509* x509)
46424632
}
46434633

46444634
#ifdef WOLFSSL_DUAL_ALG_CERTS
4645-
if (x509->sapkiDer) {
4646-
XFREE(x509->sapkiDer, x509->heap, DYNAMIC_TYPE_X509_EXT);
4647-
x509->sapkiDer = NULL;
4648-
}
4649-
if (x509->altSigAlgDer) {
4650-
XFREE(x509->altSigAlgDer, x509->heap, DYNAMIC_TYPE_X509_EXT);
4651-
x509->altSigAlgDer = NULL;
4652-
}
4635+
XFREE(x509->sapkiDer, x509->heap, DYNAMIC_TYPE_X509_EXT);
4636+
x509->sapkiDer = NULL;
4637+
XFREE(x509->altSigAlgDer, x509->heap, DYNAMIC_TYPE_X509_EXT);
4638+
x509->altSigAlgDer = NULL;
46534639
if (x509->altSigValDer) {
46544640
XFREE(x509->altSigValDer, x509->heap, DYNAMIC_TYPE_X509_EXT);
46554641
x509->altSigValDer= NULL;
@@ -13825,15 +13811,11 @@ static void FreeProcPeerCertArgs(WOLFSSL* ssl, void* pArgs)
1382513811

1382613812
(void)ssl;
1382713813

13828-
if (args->certs) {
13829-
XFREE(args->certs, ssl->heap, DYNAMIC_TYPE_DER);
13830-
args->certs = NULL;
13831-
}
13814+
XFREE(args->certs, ssl->heap, DYNAMIC_TYPE_DER);
13815+
args->certs = NULL;
1383213816
#ifdef WOLFSSL_TLS13
13833-
if (args->exts) {
13834-
XFREE(args->exts, ssl->heap, DYNAMIC_TYPE_CERT_EXT);
13835-
args->exts = NULL;
13836-
}
13817+
XFREE(args->exts, ssl->heap, DYNAMIC_TYPE_CERT_EXT);
13818+
args->exts = NULL;
1383713819
#endif
1383813820
if (args->dCert) {
1383913821
if (args->dCertInit) {
@@ -30495,10 +30477,8 @@ static void FreeDskeArgs(WOLFSSL* ssl, void* pArgs)
3049530477

3049630478
#if !defined(NO_DH) || defined(HAVE_ECC) || defined(HAVE_CURVE25519) || \
3049730479
defined(HAVE_CURVE448)
30498-
if (args->verifySig) {
30499-
XFREE(args->verifySig, ssl->heap, DYNAMIC_TYPE_SIGNATURE);
30500-
args->verifySig = NULL;
30501-
}
30480+
XFREE(args->verifySig, ssl->heap, DYNAMIC_TYPE_SIGNATURE);
30481+
args->verifySig = NULL;
3050230482
#endif
3050330483
}
3050430484

@@ -31834,14 +31814,10 @@ static void FreeSckeArgs(WOLFSSL* ssl, void* pArgs)
3183431814

3183531815
(void)ssl;
3183631816

31837-
if (args->encSecret) {
31838-
XFREE(args->encSecret, ssl->heap, DYNAMIC_TYPE_SECRET);
31839-
args->encSecret = NULL;
31840-
}
31841-
if (args->input) {
31842-
XFREE(args->input, ssl->heap, DYNAMIC_TYPE_IN_BUFFER);
31843-
args->input = NULL;
31844-
}
31817+
XFREE(args->encSecret, ssl->heap, DYNAMIC_TYPE_SECRET);
31818+
args->encSecret = NULL;
31819+
XFREE(args->input, ssl->heap, DYNAMIC_TYPE_IN_BUFFER);
31820+
args->input = NULL;
3184531821
}
3184631822

3184731823
/* handle generation client_key_exchange (16) */
@@ -33106,15 +33082,11 @@ static void FreeScvArgs(WOLFSSL* ssl, void* pArgs)
3310633082
(void)ssl;
3310733083

3310833084
#ifndef NO_RSA
33109-
if (args->verifySig) {
33110-
XFREE(args->verifySig, ssl->heap, DYNAMIC_TYPE_SIGNATURE);
33111-
args->verifySig = NULL;
33112-
}
33085+
XFREE(args->verifySig, ssl->heap, DYNAMIC_TYPE_SIGNATURE);
33086+
args->verifySig = NULL;
3311333087
#endif
33114-
if (args->input) {
33115-
XFREE(args->input, ssl->heap, DYNAMIC_TYPE_IN_BUFFER);
33116-
args->input = NULL;
33117-
}
33088+
XFREE(args->input, ssl->heap, DYNAMIC_TYPE_IN_BUFFER);
33089+
args->input = NULL;
3311833090
}
3311933091

3312033092
/* handle generation of certificate_verify (15) */
@@ -34233,16 +34205,12 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3423334205
(void)ssl;
3423434206

3423534207
#if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)
34236-
if (args->exportBuf) {
34237-
XFREE(args->exportBuf, ssl->heap, DYNAMIC_TYPE_DER);
34238-
args->exportBuf = NULL;
34239-
}
34208+
XFREE(args->exportBuf, ssl->heap, DYNAMIC_TYPE_DER);
34209+
args->exportBuf = NULL;
3424034210
#endif
3424134211
#ifndef NO_RSA
34242-
if (args->verifySig) {
34243-
XFREE(args->verifySig, ssl->heap, DYNAMIC_TYPE_SIGNATURE);
34244-
args->verifySig = NULL;
34245-
}
34212+
XFREE(args->verifySig, ssl->heap, DYNAMIC_TYPE_SIGNATURE);
34213+
args->verifySig = NULL;
3424634214
#endif
3424734215
(void)args;
3424834216
}

src/ocsp.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -824,10 +824,8 @@ WOLFSSL_OCSP_CERTID* wolfSSL_OCSP_cert_to_id(
824824
if (ret != 0) {
825825
if (derCert != NULL)
826826
FreeDer(&derCert);
827-
if (certId != NULL) {
828-
XFREE(certId, cm->heap, DYNAMIC_TYPE_OPENSSL);
829-
certId = NULL;
830-
}
827+
XFREE(certId, cm->heap, DYNAMIC_TYPE_OPENSSL);
828+
certId = NULL;
831829
XFREE(certStatus, cm->heap, DYNAMIC_TYPE_OPENSSL);
832830
}
833831

@@ -1104,10 +1102,8 @@ WOLFSSL_OCSP_BASICRESP* wolfSSL_OCSP_response_get1_basic(OcspResponse* response)
11041102
DYNAMIC_TYPE_OCSP_ENTRY);
11051103
bs->source = (byte*)XMALLOC(bs->maxIdx, NULL, DYNAMIC_TYPE_TMP_BUFFER);
11061104
if (bs->single == NULL || bs->source == NULL) {
1107-
if (bs->single) {
1108-
XFREE(bs->single, NULL, DYNAMIC_TYPE_OCSP_ENTRY);
1109-
bs->single = NULL;
1110-
}
1105+
XFREE(bs->single, NULL, DYNAMIC_TYPE_OCSP_ENTRY);
1106+
bs->single = NULL;
11111107
wolfSSL_OCSP_RESPONSE_free(bs);
11121108
bs = NULL;
11131109
}

src/sniffer.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -854,10 +854,8 @@ static void FreeSnifferSession(SnifferSession* session)
854854
XFREE(session->cliKeyShare, NULL, DYNAMIC_TYPE_TMP_BUFFER);
855855
#endif
856856
#ifdef HAVE_MAX_FRAGMENT
857-
if (session->tlsFragBuf) {
858-
XFREE(session->tlsFragBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
859-
session->tlsFragBuf = NULL;
860-
}
857+
XFREE(session->tlsFragBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
858+
session->tlsFragBuf = NULL;
861859
#endif
862860
}
863861
XFREE(session, NULL, DYNAMIC_TYPE_SNIFFER_SESSION);
@@ -4722,10 +4720,8 @@ static int DoHandShake(const byte* input, int* sslBytes,
47224720
exit:
47234721
#endif
47244722
#ifdef HAVE_MAX_FRAGMENT
4725-
if (session->tlsFragBuf) {
4726-
XFREE(session->tlsFragBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
4727-
session->tlsFragBuf = NULL;
4728-
}
4723+
XFREE(session->tlsFragBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
4724+
session->tlsFragBuf = NULL;
47294725
#endif
47304726

47314727
*sslBytes = startBytes - size; /* actual bytes of full process */

src/ssl.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,10 +1130,8 @@ void wolfSSL_CTX_free(WOLFSSL_CTX* ctx)
11301130
#if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) \
11311131
&& !defined(NO_SHA256) && !defined(WC_NO_RNG)
11321132
if (ctx->srp != NULL) {
1133-
if (ctx->srp_password != NULL){
1134-
XFREE(ctx->srp_password, ctx->heap, DYNAMIC_TYPE_SRP);
1135-
ctx->srp_password = NULL;
1136-
}
1133+
XFREE(ctx->srp_password, ctx->heap, DYNAMIC_TYPE_SRP);
1134+
ctx->srp_password = NULL;
11371135
wc_SrpTerm(ctx->srp);
11381136
XFREE(ctx->srp, ctx->heap, DYNAMIC_TYPE_SRP);
11391137
ctx->srp = NULL;
@@ -11551,11 +11549,8 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
1155111549
wc_FreeRng(&rng);
1155211550
return WOLFSSL_FAILURE;
1155311551
}
11554-
if (ctx->srp_password != NULL){
11555-
XFREE(ctx->srp_password,NULL,
11556-
DYNAMIC_TYPE_SRP);
11557-
ctx->srp_password = NULL;
11558-
}
11552+
XFREE(ctx->srp_password, NULL, DYNAMIC_TYPE_SRP);
11553+
ctx->srp_password = NULL;
1155911554
wc_FreeRng(&rng);
1156011555
} else {
1156111556
/* save password for wolfSSL_set_srp_username */
@@ -23633,10 +23628,8 @@ int wolfSSL_BUF_MEM_resize(WOLFSSL_BUF_MEM* buf, size_t len)
2363323628
void wolfSSL_BUF_MEM_free(WOLFSSL_BUF_MEM* buf)
2363423629
{
2363523630
if (buf) {
23636-
if (buf->data) {
23637-
XFREE(buf->data, NULL, DYNAMIC_TYPE_OPENSSL);
23638-
buf->data = NULL;
23639-
}
23631+
XFREE(buf->data, NULL, DYNAMIC_TYPE_OPENSSL);
23632+
buf->data = NULL;
2364023633
buf->max = 0;
2364123634
buf->length = 0;
2364223635
XFREE(buf, NULL, DYNAMIC_TYPE_OPENSSL);

src/ssl_sess.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,16 +1329,12 @@ int wolfSSL_GetSessionFromCache(WOLFSSL* ssl, WOLFSSL_SESSION* output)
13291329
output->ticketLenAlloc = 0;
13301330
}
13311331
#ifdef WOLFSSL_TLS13
1332-
if (preallocNonce != NULL) {
1333-
XFREE(preallocNonce, output->heap, DYNAMIC_TYPE_SESSION_TICK);
1334-
preallocNonce = NULL;
1335-
}
1332+
XFREE(preallocNonce, output->heap, DYNAMIC_TYPE_SESSION_TICK);
1333+
preallocNonce = NULL;
13361334
#endif /* WOLFSSL_TLS13 */
13371335
#ifdef WOLFSSL_SMALL_STACK
1338-
if (tmpTicket != NULL) {
1339-
XFREE(tmpTicket, output->heap, DYNAMIC_TYPE_TMP_BUFFER);
1340-
tmpTicket = NULL;
1341-
}
1336+
XFREE(tmpTicket, output->heap, DYNAMIC_TYPE_TMP_BUFFER);
1337+
tmpTicket = NULL;
13421338
#endif
13431339
#endif
13441340
}

0 commit comments

Comments
 (0)