diff --git a/src/bio.c b/src/bio.c index 43492126df..494234c735 100644 --- a/src/bio.c +++ b/src/bio.c @@ -834,9 +834,7 @@ int wolfSSL_BIO_write(WOLFSSL_BIO* bio, const void* data, int len) (const char*)data, len, 0, ret); } - if (frmt != NULL) { - XFREE(frmt, front->heap, DYNAMIC_TYPE_TMP_BUFFER); - } + XFREE(frmt, front->heap, DYNAMIC_TYPE_TMP_BUFFER); #ifdef WOLFSSL_BASE64_ENCODE if (retB64 > 0 && ret > 0) @@ -2969,9 +2967,7 @@ int wolfSSL_BIO_flush(WOLFSSL_BIO* bio) bio->pair->pair = NULL; } - if (bio->ip != NULL) { - XFREE(bio->ip, bio->heap, DYNAMIC_TYPE_OPENSSL); - } + XFREE(bio->ip, bio->heap, DYNAMIC_TYPE_OPENSSL); if (bio->shutdown) { if (bio->type == WOLFSSL_BIO_SSL && bio->ptr.ssl) diff --git a/src/dtls13.c b/src/dtls13.c index 0577715474..4d2365f38a 100644 --- a/src/dtls13.c +++ b/src/dtls13.c @@ -811,9 +811,7 @@ static void Dtls13MaybeSaveClientHello(WOLFSSL* ssl) while (r != NULL) { if (r->handshakeType == client_hello) { Dtls13RtxRecordUnlink(ssl, prev_next, r); - if (ssl->dtls13ClientHello != NULL) - XFREE(ssl->dtls13ClientHello, ssl->heap, - DYNAMIC_TYPE_DTLS_MSG); + XFREE(ssl->dtls13ClientHello, ssl->heap, DYNAMIC_TYPE_DTLS_MSG); ssl->dtls13ClientHello = r->data; ssl->dtls13ClientHelloSz = r->length; r->data = NULL; diff --git a/src/internal.c b/src/internal.c index 7d02dce0a8..d31209dede 100644 --- a/src/internal.c +++ b/src/internal.c @@ -4564,9 +4564,7 @@ void FreeX509(WOLFSSL_X509* x509) XFREE(x509->sig.buffer, x509->heap, DYNAMIC_TYPE_SIGNATURE); x509->sig.buffer = NULL; #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) - if (x509->authKeyIdSrc != NULL) { - XFREE(x509->authKeyIdSrc, x509->heap, DYNAMIC_TYPE_X509_EXT); - } + XFREE(x509->authKeyIdSrc, x509->heap, DYNAMIC_TYPE_X509_EXT); else { XFREE(x509->authKeyId, x509->heap, DYNAMIC_TYPE_X509_EXT); } @@ -4588,9 +4586,7 @@ void FreeX509(WOLFSSL_X509* x509) } #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || \ defined(WOLFSSL_QT) - if (x509->authInfoCaIssuer != NULL) { - XFREE(x509->authInfoCaIssuer, x509->heap, DYNAMIC_TYPE_X509_EXT); - } + XFREE(x509->authInfoCaIssuer, x509->heap, DYNAMIC_TYPE_X509_EXT); if (x509->ext_sk != NULL) { wolfSSL_sk_X509_EXTENSION_pop_free(x509->ext_sk, NULL); } @@ -8375,9 +8371,7 @@ void SSL_ResourceFree(WOLFSSL* ssl) } #endif #ifdef OPENSSL_EXTRA - if (ssl->param) { - XFREE(ssl->param, ssl->heap, DYNAMIC_TYPE_OPENSSL); - } + XFREE(ssl->param, ssl->heap, DYNAMIC_TYPE_OPENSSL); #endif #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH) while (ssl->certReqCtx != NULL) { @@ -13261,12 +13255,9 @@ static int ProcessCSR(WOLFSSL* ssl, byte* input, word32* inOutIdx, DYNAMIC_TYPE_OCSP_REQUEST); if (status == NULL || single == NULL || response == NULL) { - if (status) - XFREE(status, ssl->heap, DYNAMIC_TYPE_OCSP_STATUS); - if (single) - XFREE(single, ssl->heap, DYNAMIC_TYPE_OCSP_ENTRY); - if (response) - XFREE(response, ssl->heap, DYNAMIC_TYPE_OCSP_REQUEST); + XFREE(status, ssl->heap, DYNAMIC_TYPE_OCSP_STATUS); + XFREE(single, ssl->heap, DYNAMIC_TYPE_OCSP_ENTRY); + XFREE(response, ssl->heap, DYNAMIC_TYPE_OCSP_REQUEST); return MEMORY_ERROR; } @@ -15033,8 +15024,7 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx, if (dCertAdd_inited) FreeDecodedCert(dCertAdd); #ifdef WOLFSSL_SMALL_STACK - if (dCertAdd) - XFREE(dCertAdd, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(dCertAdd, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER); #endif if (ret != 0) goto exit_ppc; @@ -16222,12 +16212,9 @@ static int DoCertificateStatus(WOLFSSL* ssl, byte* input, word32* inOutIdx, DYNAMIC_TYPE_OCSP_REQUEST); if (status == NULL || single == NULL || response == NULL) { - if (status) - XFREE(status, ssl->heap, DYNAMIC_TYPE_OCSP_STATUS); - if (single) - XFREE(single, ssl->heap, DYNAMIC_TYPE_OCSP_ENTRY); - if (response) - XFREE(response, ssl->heap, DYNAMIC_TYPE_OCSP_REQUEST); + XFREE(status, ssl->heap, DYNAMIC_TYPE_OCSP_STATUS); + XFREE(single, ssl->heap, DYNAMIC_TYPE_OCSP_ENTRY); + XFREE(response, ssl->heap, DYNAMIC_TYPE_OCSP_REQUEST); return MEMORY_ERROR; } @@ -37152,8 +37139,7 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx, ssl->clSuites = NULL; #endif #ifdef WOLFSSL_SMALL_STACK - if (clSuites != NULL) - XFREE(clSuites, ssl->heap, DYNAMIC_TYPE_SUITES); + XFREE(clSuites, ssl->heap, DYNAMIC_TYPE_SUITES); #endif WOLFSSL_LEAVE("DoClientHello", ret); WOLFSSL_END(WC_FUNC_CLIENT_HELLO_DO); diff --git a/src/ocsp.c b/src/ocsp.c index 97a0adc916..0dfdf5d36e 100644 --- a/src/ocsp.c +++ b/src/ocsp.c @@ -374,10 +374,7 @@ int CheckOcspResponse(WOLFSSL_OCSP *ocsp, byte *response, int responseSz, } if (status != NULL) { - if (status->rawOcspResponse) { - XFREE(status->rawOcspResponse, ocsp->cm->heap, - DYNAMIC_TYPE_OCSP_STATUS); - } + XFREE(status->rawOcspResponse, ocsp->cm->heap, DYNAMIC_TYPE_OCSP_STATUS); /* Replace existing certificate entry with updated */ ocspResponse->single->status->next = status->next; @@ -831,13 +828,11 @@ WOLFSSL_OCSP_CERTID* wolfSSL_OCSP_cert_to_id( XFREE(certId, cm->heap, DYNAMIC_TYPE_OPENSSL); certId = NULL; } - if (certStatus) - XFREE(certStatus, cm->heap, DYNAMIC_TYPE_OPENSSL); + XFREE(certStatus, cm->heap, DYNAMIC_TYPE_OPENSSL); } #ifdef WOLFSSL_SMALL_STACK - if (cert != NULL) - XFREE(cert, cm->heap, DYNAMIC_TYPE_DCERT); + XFREE(cert, cm->heap, DYNAMIC_TYPE_DCERT); #endif if (cm != NULL) @@ -1167,8 +1162,7 @@ WOLFSSL_OCSP_ONEREQ* wolfSSL_OCSP_request_add0_id(OcspRequest *req, XMEMCPY(req->issuerHash, cid->issuerHash, KEYID_SIZE); XMEMCPY(req->issuerKeyHash, cid->issuerKeyHash, KEYID_SIZE); if (cid->status->serialSz > req->serialSz) { - if (req->serial != NULL) - XFREE(req->serial, req->heap, DYNAMIC_TYPE_OCSP); + XFREE(req->serial, req->heap, DYNAMIC_TYPE_OCSP); req->serial = (byte*)XMALLOC((size_t)cid->status->serialSz, req->heap, DYNAMIC_TYPE_OCSP_REQUEST); if (req->serial == NULL) diff --git a/src/pk.c b/src/pk.c index 84e92edd42..8b8dd97737 100644 --- a/src/pk.c +++ b/src/pk.c @@ -4691,8 +4691,7 @@ int wolfSSL_RSA_GenAdd(WOLFSSL_RSA* rsa) mp_clear(t); #ifdef WOLFSSL_SMALL_STACK - if (tmp != NULL) - XFREE(tmp, rsa->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(tmp, rsa->heap, DYNAMIC_TYPE_TMP_BUFFER); #endif return ret; diff --git a/src/ssl.c b/src/ssl.c index 0afee747c8..be63f6b836 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -11559,8 +11559,7 @@ int wolfSSL_set_compression(WOLFSSL* ssl) wc_FreeRng(&rng); } else { /* save password for wolfSSL_set_srp_username */ - if (ctx->srp_password != NULL) - XFREE(ctx->srp_password,ctx->heap, DYNAMIC_TYPE_SRP); + XFREE(ctx->srp_password, ctx->heap, DYNAMIC_TYPE_SRP); ctx->srp_password = (byte*)XMALLOC(XSTRLEN(password) + 1, ctx->heap, DYNAMIC_TYPE_SRP); @@ -13572,9 +13571,7 @@ WOLFSSL_STACK* wolfSSL_sk_new_node(void* heap) /* free's node but does not free internal data such as in->data.x509 */ void wolfSSL_sk_free_node(WOLFSSL_STACK* in) { - if (in != NULL) { - XFREE(in, in->heap, DYNAMIC_TYPE_OPENSSL); - } + XFREE(in, in->heap, DYNAMIC_TYPE_OPENSSL); } /* pushes node "in" onto "stack" and returns pointer to the new stack on success diff --git a/src/ssl_certman.c b/src/ssl_certman.c index f9d87450ec..d520f24708 100644 --- a/src/ssl_certman.c +++ b/src/ssl_certman.c @@ -1382,9 +1382,7 @@ int CM_SaveCertCache(WOLFSSL_CERT_MANAGER* cm, const char* fname) ret = FWRITE_ERROR; } } - if (mem != NULL) { - XFREE(mem, cm->heap, DYNAMIC_TYPE_TMP_BUFFER); - } + XFREE(mem, cm->heap, DYNAMIC_TYPE_TMP_BUFFER); /* Unlock CA table. */ wc_UnLockMutex(&cm->caLock); diff --git a/src/ssl_p7p12.c b/src/ssl_p7p12.c index f76f5174ed..a60a356a8e 100644 --- a/src/ssl_p7p12.c +++ b/src/ssl_p7p12.c @@ -714,9 +714,7 @@ int wolfSSL_PKCS7_final(PKCS7* pkcs7, WOLFSSL_BIO* in, int flags) } } - if (mem != NULL) { - XFREE(mem, in->heap, DYNAMIC_TYPE_TMP_BUFFER); - } + XFREE(mem, in->heap, DYNAMIC_TYPE_TMP_BUFFER); } else { #ifdef HAVE_SMIME @@ -1034,19 +1032,11 @@ int wolfSSL_PEM_write_bio_PKCS7(WOLFSSL_BIO* bio, PKCS7* p7) error: #ifdef WOLFSSL_SMALL_STACK - if (outputHead) { - XFREE(outputHead, bio->heap, DYNAMIC_TYPE_TMP_BUFFER); - } - if (outputFoot) { - XFREE(outputFoot, bio->heap, DYNAMIC_TYPE_TMP_BUFFER); - } + XFREE(outputHead, bio->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(outputFoot, bio->heap, DYNAMIC_TYPE_TMP_BUFFER); #endif - if (output) { - XFREE(output, bio->heap, DYNAMIC_TYPE_TMP_BUFFER); - } - if (pem) { - XFREE(pem, bio->heap, DYNAMIC_TYPE_TMP_BUFFER); - } + XFREE(output, bio->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(pem, bio->heap, DYNAMIC_TYPE_TMP_BUFFER); return WOLFSSL_FAILURE; } @@ -1692,8 +1682,7 @@ WC_PKCS12* wolfSSL_d2i_PKCS12_bio(WOLFSSL_BIO* bio, WC_PKCS12** pkcs12) } /* cleanup */ - if (mem != NULL) - XFREE(mem, bio->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(mem, bio->heap, DYNAMIC_TYPE_TMP_BUFFER); if (ret < 0 && localPkcs12 != NULL) { wc_PKCS12_free(localPkcs12); localPkcs12 = NULL; diff --git a/src/ssl_sess.c b/src/ssl_sess.c index 90b09b7363..29bf7f5cbb 100644 --- a/src/ssl_sess.c +++ b/src/ssl_sess.c @@ -1309,8 +1309,7 @@ int wolfSSL_GetSessionFromCache(WOLFSSL* ssl, WOLFSSL_SESSION* output) output->ticketLenAlloc = 0; } #ifdef WOLFSSL_SMALL_STACK - if (tmpTicket != NULL) - XFREE(tmpTicket, output->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(tmpTicket, output->heap, DYNAMIC_TYPE_TMP_BUFFER); #endif return WOLFSSL_FAILURE; } @@ -1417,8 +1416,7 @@ int wolfSSL_GetSessionFromCache(WOLFSSL* ssl, WOLFSSL_SESSION* output) } } #ifdef WOLFSSL_SMALL_STACK - if (tmpTicket != NULL) - XFREE(tmpTicket, output->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(tmpTicket, output->heap, DYNAMIC_TYPE_TMP_BUFFER); #endif #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_TICKET_NONCE_MALLOC) && \ @@ -1455,8 +1453,7 @@ int wolfSSL_GetSessionFromCache(WOLFSSL* ssl, WOLFSSL_SESSION* output) preallocNonce = NULL; } } - if (preallocNonce != NULL) - XFREE(preallocNonce, output->heap, DYNAMIC_TYPE_SESSION_TICK); + XFREE(preallocNonce, output->heap, DYNAMIC_TYPE_SESSION_TICK); #endif /* WOLFSSL_TLS13 && WOLFSSL_TICKET_NONCE_MALLOC && FIPS_VERSION_GE(5,3)*/ #endif @@ -1839,8 +1836,7 @@ int AddSessionToCache(WOLFSSL_CTX* ctx, WOLFSSL_SESSION* addSession, preallocNonce = (byte*)XMALLOC(addSession->ticketNonce.len, addSession->heap, DYNAMIC_TYPE_SESSION_TICK); if (preallocNonce == NULL) { - if (ticBuff != NULL) - XFREE(ticBuff, addSession->heap, DYNAMIC_TYPE_SESSION_TICK); + XFREE(ticBuff, addSession->heap, DYNAMIC_TYPE_SESSION_TICK); return MEMORY_E; } preallocNonceLen = addSession->ticketNonce.len; @@ -3906,8 +3902,7 @@ static int wolfSSL_DupSessionEx(const WOLFSSL_SESSION* input, } } else { - if (ticBuff != NULL) - XFREE(ticBuff, output->heap, DYNAMIC_TYPE_SESSION_TICK); + XFREE(ticBuff, output->heap, DYNAMIC_TYPE_SESSION_TICK); output->ticket = output->staticTicket; output->ticketLenAlloc = 0; } diff --git a/src/tls.c b/src/tls.c index 242afbcea9..e8941baab8 100644 --- a/src/tls.c +++ b/src/tls.c @@ -6744,8 +6744,7 @@ int TLSX_Cookie_Use(const WOLFSSL* ssl, const byte* data, word16 len, byte* mac, if (mac != NULL) XMEMCPY(cookie->data + len, mac, macSz); - if (extension->data != NULL) - XFREE(extension->data, ssl->heap, DYNAMIC_TYPE_TLSX); + XFREE(extension->data, ssl->heap, DYNAMIC_TYPE_TLSX); extension->data = (void*)cookie; extension->resp = (byte)resp; @@ -7953,10 +7952,8 @@ static int TLSX_KeyShare_GenPqcKey(WOLFSSL *ssl, KeyShareEntry* kse) wc_KyberKey_Free(kem); TLSX_KeyShare_FreeAll(ecc_kse, ssl->heap); - if (pubKey != NULL) - XFREE(pubKey, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY); - if (privKey != NULL) - XFREE(privKey, ssl->heap, DYNAMIC_TYPE_PRIVATE_KEY); + XFREE(pubKey, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY); + XFREE(privKey, ssl->heap, DYNAMIC_TYPE_PRIVATE_KEY); return ret; } @@ -8731,9 +8728,7 @@ static int TLSX_KeyShare_ProcessPqc(WOLFSSL* ssl, KeyShareEntry* keyShareEntry) ssl->arrays->preMasterSz = (word32) sharedSecretLen; } - if (sharedSecret != NULL) { - XFREE(sharedSecret, ssl->heap, DYNAMIC_TYPE_SECRET); - } + XFREE(sharedSecret, ssl->heap, DYNAMIC_TYPE_SECRET); wc_ecc_free(&eccpubkey); wc_KyberKey_Free(kem); @@ -9220,9 +9215,7 @@ static int server_generate_pqc_ciphertext(WOLFSSL* ssl, } if (ret == 0) { - if (keyShareEntry->ke != NULL) { - XFREE(keyShareEntry->ke, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY); - } + XFREE(keyShareEntry->ke, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY); keyShareEntry->ke = sharedSecret; keyShareEntry->keLen = outlen + ssSz; @@ -9240,10 +9233,8 @@ static int server_generate_pqc_ciphertext(WOLFSSL* ssl, } TLSX_KeyShare_FreeAll(ecc_kse, ssl->heap); - if (sharedSecret != NULL) - XFREE(sharedSecret, ssl->heap, DYNAMIC_TYPE_SECRET); - if (ciphertext != NULL) - XFREE(ciphertext, ssl->heap, DYNAMIC_TYPE_TLSX); + XFREE(sharedSecret, ssl->heap, DYNAMIC_TYPE_SECRET); + XFREE(ciphertext, ssl->heap, DYNAMIC_TYPE_TLSX); wc_ecc_free(&eccpubkey); wc_KyberKey_Free(kem); return ret; @@ -9308,9 +9299,7 @@ int TLSX_KeyShare_Use(const WOLFSSL* ssl, word16 group, word16 len, byte* data, else #endif if (data != NULL) { - if (keyShareEntry->ke != NULL) { - XFREE(keyShareEntry->ke, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY); - } + XFREE(keyShareEntry->ke, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY); keyShareEntry->ke = data; keyShareEntry->keLen = len; } diff --git a/src/x509.c b/src/x509.c index 8d9c1004af..e34e6b7ab1 100644 --- a/src/x509.c +++ b/src/x509.c @@ -6391,9 +6391,7 @@ static int X509PrintExtensions(WOLFSSL_BIO* bio, WOLFSSL_X509* x509, int indent) } } - if (buf != NULL) { - XFREE(buf, x509->heap, DYNAMIC_TYPE_TMP_BUFFER); - } + XFREE(buf, x509->heap, DYNAMIC_TYPE_TMP_BUFFER); return ret; } @@ -7189,8 +7187,7 @@ int wolfSSL_X509_LOOKUP_load_file(WOLFSSL_X509_LOOKUP* lookup, while (ret == WOLFSSL_SUCCESS); end: - if (pem != NULL) - XFREE(pem, 0, DYNAMIC_TYPE_PEM); + XFREE(pem, 0, DYNAMIC_TYPE_PEM); XFCLOSE(fp); return WS_RETURN_CODE(ret, (int)WOLFSSL_FAILURE); #else @@ -7966,9 +7963,7 @@ WOLFSSL_API WOLFSSL_X509_CRL *wolfSSL_d2i_X509_CRL_bio(WOLFSSL_BIO *bp, } } - if (der != NULL) { - XFREE(der, 0, DYNAMIC_TYPE_DER); - } + XFREE(der, 0, DYNAMIC_TYPE_DER); return crl; } @@ -9689,9 +9684,7 @@ WOLF_STACK_OF(WOLFSSL_X509)* wolfSSL_X509_chain_up_ref( { WOLFSSL_ENTER("wolfSSL_X509_NAME_free"); FreeX509Name(name); - if (name != NULL) { - XFREE(name, name->heap, DYNAMIC_TYPE_X509); - } + XFREE(name, name->heap, DYNAMIC_TYPE_X509); } @@ -11404,9 +11397,7 @@ int wolfSSL_i2d_X509_NAME(WOLFSSL_X509_NAME* name, unsigned char** out) } err: - if(pem != NULL) { - XFREE(pem, 0, DYNAMIC_TYPE_PEM); - } + XFREE(pem, 0, DYNAMIC_TYPE_PEM); if(der != NULL) { FreeDer(&der); } @@ -11768,8 +11759,7 @@ int wolfSSL_i2d_X509_NAME(WOLFSSL_X509_NAME* name, unsigned char** out) #endif return WOLFSSL_SUCCESS; err: - if (pem) - XFREE(pem, 0, DYNAMIC_TYPE_PEM); + XFREE(pem, 0, DYNAMIC_TYPE_PEM); #ifdef HAVE_CRL if (der) FreeDer(&der); @@ -13515,8 +13505,7 @@ int wolfSSL_X509_check_ip_asc(WOLFSSL_X509 *x, const char *ipasc, } #ifdef WOLFSSL_SMALL_STACK - if (dCert != NULL) - XFREE(dCert, x->heap, DYNAMIC_TYPE_DCERT); + XFREE(dCert, x->heap, DYNAMIC_TYPE_DCERT); #endif return ret; diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 16059e1c45..ec4e6b590b 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -11550,8 +11550,7 @@ void FreeDecodedCert(DecodedCert* cert) wolfSSL_X509_NAME_free((WOLFSSL_X509_NAME*)cert->subjectName); #endif /* WOLFSSL_X509_NAME_AVAILABLE */ #if defined(WOLFSSL_RENESAS_TSIP_TLS) || defined(WOLFSSL_RENESAS_FSPSM_TLS) - if (cert->sce_tsip_encRsaKeyIdx != NULL) - XFREE(cert->sce_tsip_encRsaKeyIdx, cert->heap, DYNAMIC_TYPE_RSA); + XFREE(cert->sce_tsip_encRsaKeyIdx, cert->heap, DYNAMIC_TYPE_RSA); #endif FreeSignatureCtx(&cert->sigCtx); } @@ -27492,12 +27491,8 @@ static int SetExtKeyUsage(Cert* cert, byte* output, word32 outSz, byte input) } /* Dispose of allocated data. */ - if (extKuASN != NULL) { - XFREE(extKuASN, cert->heap, DYNAMIC_TYPE_TMP_BUFFER); - } - if (dataASN != NULL) { - XFREE(dataASN, cert->heap, DYNAMIC_TYPE_TMP_BUFFER); - } + XFREE(extKuASN, cert->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(dataASN, cert->heap, DYNAMIC_TYPE_TMP_BUFFER); return ret; #endif @@ -37474,8 +37469,7 @@ void FreeOcspRequest(OcspRequest* req) WOLFSSL_ENTER("FreeOcspRequest"); if (req) { - if (req->serial) - XFREE(req->serial, req->heap, DYNAMIC_TYPE_OCSP_REQUEST); + XFREE(req->serial, req->heap, DYNAMIC_TYPE_OCSP_REQUEST); req->serial = NULL; #ifdef OPENSSL_EXTRA @@ -37488,8 +37482,7 @@ void FreeOcspRequest(OcspRequest* req) req->serialInt = NULL; #endif - if (req->url) - XFREE(req->url, req->heap, DYNAMIC_TYPE_OCSP_REQUEST); + XFREE(req->url, req->heap, DYNAMIC_TYPE_OCSP_REQUEST); req->url = NULL; #ifdef OPENSSL_EXTRA diff --git a/wolfcrypt/src/cmac.c b/wolfcrypt/src/cmac.c index a31d374865..8accb1a872 100644 --- a/wolfcrypt/src/cmac.c +++ b/wolfcrypt/src/cmac.c @@ -242,9 +242,7 @@ int wc_CmacFree(Cmac* cmac) /* TODO: msg is leaked if wc_CmacFinal() is not called * e.g. when multiple calls to wc_CmacUpdate() and one fails but * wc_CmacFinal() not called. */ - if (cmac->msg != NULL) { - XFREE(cmac->msg, cmac->heap, DYNAMIC_TYPE_TMP_BUFFER); - } + XFREE(cmac->msg, cmac->heap, DYNAMIC_TYPE_TMP_BUFFER); #endif wc_AesFree(&cmac->aes); ForceZero(cmac, sizeof(Cmac)); diff --git a/wolfcrypt/src/dilithium.c b/wolfcrypt/src/dilithium.c index 521353c608..ad6a73f0d7 100644 --- a/wolfcrypt/src/dilithium.c +++ b/wolfcrypt/src/dilithium.c @@ -7935,9 +7935,7 @@ int wc_dilithium_check_key(dilithium_key* key) } /* Dispose of allocated memory. */ - if (s1 != NULL) { - XFREE(s1, key->heap, DYNAMIC_TYPE_DILITHIUM); - } + XFREE(s1, key->heap, DYNAMIC_TYPE_DILITHIUM); #else /* Validate parameter. */ if (key == NULL) { diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index e336b39af6..46d7da16c3 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -4976,8 +4976,7 @@ int wc_ecc_shared_secret_gen_sync(ecc_key* private_key, ecc_point* point, if (k == k_lcl) mp_clear(k); #ifdef WOLFSSL_SMALL_STACK - if (k_lcl != NULL) - XFREE(k_lcl, private_key->heap, DYNAMIC_TYPE_ECC_BUFFER); + XFREE(k_lcl, private_key->heap, DYNAMIC_TYPE_ECC_BUFFER); #endif #endif @@ -14857,9 +14856,7 @@ int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg, #endif #ifdef WOLFSSL_SMALL_STACK #ifndef WOLFSSL_ECIES_OLD - if (peerKey != NULL) { - XFREE(peerKey, ctx->heap, DYNAMIC_TYPE_ECC_BUFFER); - } + XFREE(peerKey, ctx->heap, DYNAMIC_TYPE_ECC_BUFFER); #endif XFREE(sharedSecret, ctx->heap, DYNAMIC_TYPE_ECC_BUFFER); XFREE(keys, ctx->heap, DYNAMIC_TYPE_ECC_BUFFER); diff --git a/wolfcrypt/src/evp.c b/wolfcrypt/src/evp.c index a5876e0675..d37d18cc47 100644 --- a/wolfcrypt/src/evp.c +++ b/wolfcrypt/src/evp.c @@ -12304,9 +12304,7 @@ struct WOLFSSL_EVP_ENCODE_CTX* wolfSSL_EVP_ENCODE_CTX_new(void) void wolfSSL_EVP_ENCODE_CTX_free(WOLFSSL_EVP_ENCODE_CTX* ctx) { WOLFSSL_ENTER("wolfSSL_EVP_ENCODE_CTX_free"); - if (ctx != NULL) { - XFREE(ctx, ctx->heap, DYNAMIC_TYPE_OPENSSL); - } + XFREE(ctx, ctx->heap, DYNAMIC_TYPE_OPENSSL); } #endif /* WOLFSSL_BASE64_ENCODE || WOLFSSL_BASE64_DECODE */ #if defined(WOLFSSL_BASE64_ENCODE) diff --git a/wolfcrypt/src/pkcs12.c b/wolfcrypt/src/pkcs12.c index 632873bbb5..cc982a3b04 100644 --- a/wolfcrypt/src/pkcs12.c +++ b/wolfcrypt/src/pkcs12.c @@ -195,12 +195,8 @@ void wc_PKCS12_free(WC_PKCS12* pkcs12) } #ifdef ASN_BER_TO_DER - if (pkcs12->der != NULL) { - XFREE(pkcs12->der, pkcs12->heap, DYNAMIC_TYPE_PKCS); - } - if (pkcs12->safeDer != NULL) { - XFREE(pkcs12->safeDer, pkcs12->heap, DYNAMIC_TYPE_PKCS); - } + XFREE(pkcs12->der, pkcs12->heap, DYNAMIC_TYPE_PKCS); + XFREE(pkcs12->safeDer, pkcs12->heap, DYNAMIC_TYPE_PKCS); #endif XFREE(pkcs12, heap, DYNAMIC_TYPE_PKCS); @@ -527,8 +523,7 @@ static int GetSignData(WC_PKCS12* pkcs12, const byte* mem, word32* idx, /* failure cleanup */ if (ret != 0) { if (mac) { - if (mac->digest) - XFREE(mac->digest, pkcs12->heap, DYNAMIC_TYPE_DIGEST); + XFREE(mac->digest, pkcs12->heap, DYNAMIC_TYPE_DIGEST); XFREE(mac, pkcs12->heap, DYNAMIC_TYPE_PKCS); } } diff --git a/wolfcrypt/src/pkcs7.c b/wolfcrypt/src/pkcs7.c index 923893c0d0..2e90a5b401 100644 --- a/wolfcrypt/src/pkcs7.c +++ b/wolfcrypt/src/pkcs7.c @@ -3374,14 +3374,11 @@ static int PKCS7_EncodeSigned(PKCS7* pkcs7, out: - if (flatSignedAttribs != NULL) - XFREE(flatSignedAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + XFREE(flatSignedAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); #ifdef WOLFSSL_SMALL_STACK - if (esd) - XFREE(esd, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER); - if (signedDataOid) - XFREE(signedDataOid, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(esd, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(signedDataOid, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER); #endif return idx; @@ -9883,13 +9880,9 @@ int wc_PKCS7_EncodeEnvelopedData(PKCS7* pkcs7, byte* output, word32 outputSz) pkcs7->cekSz, tmpIv, blockSz, NULL, 0, NULL, 0, plain, encryptedOutSz, encryptedContent); if (ret != 0) { - if (encryptedContent != NULL) { - XFREE(encryptedContent, pkcs7->heap, DYNAMIC_TYPE_PKCS7); - } + XFREE(encryptedContent, pkcs7->heap, DYNAMIC_TYPE_PKCS7); - if (plain != NULL) { - XFREE(plain, pkcs7->heap, DYNAMIC_TYPE_PKCS7); - } + XFREE(plain, pkcs7->heap, DYNAMIC_TYPE_PKCS7); wc_PKCS7_FreeEncodedRecipientSet(pkcs7); return ret; @@ -9935,13 +9928,9 @@ int wc_PKCS7_EncodeEnvelopedData(PKCS7* pkcs7, byte* output, word32 outputSz) idx += encryptedOutSz; } - if (plain != NULL) { - XFREE(plain, pkcs7->heap, DYNAMIC_TYPE_PKCS7); - } + XFREE(plain, pkcs7->heap, DYNAMIC_TYPE_PKCS7); - if (encryptedContent != NULL) { - XFREE(encryptedContent, pkcs7->heap, DYNAMIC_TYPE_PKCS7); - } + XFREE(encryptedContent, pkcs7->heap, DYNAMIC_TYPE_PKCS7); return idx; } @@ -12817,10 +12806,8 @@ int wc_PKCS7_EncodeAuthEnvelopedData(PKCS7* pkcs7, byte* output, DYNAMIC_TYPE_PKCS7); if (flatUnauthAttribs == NULL) { wc_PKCS7_FreeEncodedRecipientSet(pkcs7); - if (aadBuffer) - XFREE(aadBuffer, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER); - if (flatAuthAttribs) - XFREE(flatAuthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + XFREE(aadBuffer, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(flatAuthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); return MEMORY_E; } @@ -12844,12 +12831,9 @@ int wc_PKCS7_EncodeAuthEnvelopedData(PKCS7* pkcs7, byte* output, plain = (byte*)XMALLOC(encryptedAllocSz, pkcs7->heap, DYNAMIC_TYPE_PKCS7); if (plain == NULL) { wc_PKCS7_FreeEncodedRecipientSet(pkcs7); - if (aadBuffer) - XFREE(aadBuffer, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER); - if (flatUnauthAttribs) - XFREE(flatUnauthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); - if (flatAuthAttribs) - XFREE(flatAuthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + XFREE(aadBuffer, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(flatUnauthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + XFREE(flatAuthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); return MEMORY_E; } @@ -12863,12 +12847,9 @@ int wc_PKCS7_EncodeAuthEnvelopedData(PKCS7* pkcs7, byte* output, if (encryptedContent == NULL) { XFREE(plain, pkcs7->heap, DYNAMIC_TYPE_PKCS7); wc_PKCS7_FreeEncodedRecipientSet(pkcs7); - if (aadBuffer) - XFREE(aadBuffer, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER); - if (flatUnauthAttribs) - XFREE(flatUnauthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); - if (flatAuthAttribs) - XFREE(flatAuthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + XFREE(aadBuffer, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(flatUnauthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + XFREE(flatAuthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); return MEMORY_E; } @@ -12887,10 +12868,8 @@ int wc_PKCS7_EncodeAuthEnvelopedData(PKCS7* pkcs7, byte* output, if (ret != 0) { wc_PKCS7_FreeEncodedRecipientSet(pkcs7); - if (flatUnauthAttribs) - XFREE(flatUnauthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); - if (flatAuthAttribs) - XFREE(flatAuthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + XFREE(flatUnauthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + XFREE(flatAuthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); XFREE(encryptedContent, pkcs7->heap, DYNAMIC_TYPE_PKCS7); return ret; } @@ -12900,10 +12879,8 @@ int wc_PKCS7_EncodeAuthEnvelopedData(PKCS7* pkcs7, byte* output, sizeof(contentType)); if (ret < 0) { wc_PKCS7_FreeEncodedRecipientSet(pkcs7); - if (flatUnauthAttribs) - XFREE(flatUnauthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); - if (flatAuthAttribs) - XFREE(flatAuthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + XFREE(flatUnauthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + XFREE(flatAuthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); XFREE(encryptedContent, pkcs7->heap, DYNAMIC_TYPE_PKCS7); return ret; } @@ -12929,10 +12906,8 @@ int wc_PKCS7_EncodeAuthEnvelopedData(PKCS7* pkcs7, byte* output, if (contentEncAlgoSz == 0) { wc_PKCS7_FreeEncodedRecipientSet(pkcs7); - if (flatUnauthAttribs) - XFREE(flatUnauthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); - if (flatAuthAttribs) - XFREE(flatAuthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + XFREE(flatUnauthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + XFREE(flatAuthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); XFREE(encryptedContent, pkcs7->heap, DYNAMIC_TYPE_PKCS7); return BAD_FUNC_ARG; } @@ -12969,10 +12944,8 @@ int wc_PKCS7_EncodeAuthEnvelopedData(PKCS7* pkcs7, byte* output, if (totalSz > (int)outputSz) { WOLFSSL_MSG("Pkcs7_encrypt output buffer too small"); wc_PKCS7_FreeEncodedRecipientSet(pkcs7); - if (flatUnauthAttribs) - XFREE(flatUnauthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); - if (flatAuthAttribs) - XFREE(flatAuthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + XFREE(flatUnauthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + XFREE(flatAuthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); XFREE(encryptedContent, pkcs7->heap, DYNAMIC_TYPE_PKCS7); return BUFFER_E; } @@ -13040,9 +13013,7 @@ int wc_PKCS7_EncodeAuthEnvelopedData(PKCS7* pkcs7, byte* output, idx += unauthAttribsSz; } - if (flatUnauthAttribs != NULL) { - XFREE(flatUnauthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); - } + XFREE(flatUnauthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); XFREE(encryptedContent, pkcs7->heap, DYNAMIC_TYPE_PKCS7); @@ -13899,10 +13870,8 @@ int wc_PKCS7_EncodeEncryptedData(PKCS7* pkcs7, byte* output, word32 outputSz) if (totalSz > (int)outputSz) { WOLFSSL_MSG("PKCS#7 output buffer too small"); - if (attribs != NULL) - XFREE(attribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); - if (flatAttribs != NULL) - XFREE(flatAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + XFREE(attribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + XFREE(flatAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); XFREE(encryptedContent, pkcs7->heap, DYNAMIC_TYPE_PKCS7); XFREE(plain, pkcs7->heap, DYNAMIC_TYPE_PKCS7); return BUFFER_E; @@ -13940,10 +13909,8 @@ int wc_PKCS7_EncodeEncryptedData(PKCS7* pkcs7, byte* output, word32 outputSz) idx += attribsSz; } - if (attribs != NULL) - XFREE(attribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); - if (flatAttribs != NULL) - XFREE(flatAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + XFREE(attribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + XFREE(flatAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); XFREE(encryptedContent, pkcs7->heap, DYNAMIC_TYPE_PKCS7); XFREE(plain, pkcs7->heap, DYNAMIC_TYPE_PKCS7); diff --git a/wolfcrypt/src/port/Renesas/renesas_fspsm_util.c b/wolfcrypt/src/port/Renesas/renesas_fspsm_util.c index 55bb0c7fce..50c34d266a 100644 --- a/wolfcrypt/src/port/Renesas/renesas_fspsm_util.c +++ b/wolfcrypt/src/port/Renesas/renesas_fspsm_util.c @@ -853,10 +853,8 @@ WOLFSSL_LOCAL int wc_fspsm_generateSessionKey(WOLFSSL *ssl, cbInfo->keyflgs_tls.bits.session_key_set = 1; } - if (key_client_aes) - XFREE(key_client_aes, aes->heap, DYNAMIC_TYPE_AES); - if (key_server_aes) - XFREE(key_server_aes, aes->heap, DYNAMIC_TYPE_AES); + XFREE(key_client_aes, aes->heap, DYNAMIC_TYPE_AES); + XFREE(key_server_aes, aes->heap, DYNAMIC_TYPE_AES); /* unlock hw */ wc_fspsm_hw_unlock(); diff --git a/wolfcrypt/src/port/devcrypto/devcrypto_rsa.c b/wolfcrypt/src/port/devcrypto/devcrypto_rsa.c index ed2491549d..0949c74a0b 100644 --- a/wolfcrypt/src/port/devcrypto/devcrypto_rsa.c +++ b/wolfcrypt/src/port/devcrypto/devcrypto_rsa.c @@ -547,21 +547,13 @@ int wc_DevCrypto_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng) #endif } - if (p != NULL) - XFREE(p, key->heap, DYNAMIC_TYPE_TMP_BUFFER); - if (q != NULL) - XFREE(q, key->heap, DYNAMIC_TYPE_TMP_BUFFER); - if (dp != NULL) - XFREE(dp, key->heap, DYNAMIC_TYPE_TMP_BUFFER); - if (dq != NULL) - XFREE(dq, key->heap, DYNAMIC_TYPE_TMP_BUFFER); - if (c != NULL) - XFREE(c, key->heap, DYNAMIC_TYPE_TMP_BUFFER); - if (n != NULL) - XFREE(n, key->heap, DYNAMIC_TYPE_TMP_BUFFER); - if (d != NULL) { - XFREE(d, key->heap, DYNAMIC_TYPE_TMP_BUFFER); - } + XFREE(p, key->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(q, key->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(dp, key->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(dq, key->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(c, key->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(n, key->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(d, key->heap, DYNAMIC_TYPE_TMP_BUFFER); (void)rng; return ret; diff --git a/wolfcrypt/src/port/kcapi/kcapi_dh.c b/wolfcrypt/src/port/kcapi/kcapi_dh.c index 65f592a385..9b69abc193 100644 --- a/wolfcrypt/src/port/kcapi/kcapi_dh.c +++ b/wolfcrypt/src/port/kcapi/kcapi_dh.c @@ -70,9 +70,7 @@ static int KcapiDh_SetParams(DhKey* key) } } - if (pkcs3 != NULL) { - XFREE(pkcs3, key->heap, DYNAMIC_TYPE_TMP_BUFFER); - } + XFREE(pkcs3, key->heap, DYNAMIC_TYPE_TMP_BUFFER); return ret; } diff --git a/wolfcrypt/src/port/kcapi/kcapi_rsa.c b/wolfcrypt/src/port/kcapi/kcapi_rsa.c index 19436aec1e..a989141354 100644 --- a/wolfcrypt/src/port/kcapi/kcapi_rsa.c +++ b/wolfcrypt/src/port/kcapi/kcapi_rsa.c @@ -76,9 +76,7 @@ static int KcapiRsa_SetPrivKey(RsaKey* key) } } - if (priv != NULL) { - XFREE(priv, key->heap, DYNAMIC_TYPE_TMP_BUFFER); - } + XFREE(priv, key->heap, DYNAMIC_TYPE_TMP_BUFFER); return ret; } @@ -167,9 +165,7 @@ static int KcapiRsa_SetPubKey(RsaKey* key) } } - if (pub != NULL) { - XFREE(pub, key->heap, DYNAMIC_TYPE_TMP_BUFFER); - } + XFREE(pub, key->heap, DYNAMIC_TYPE_TMP_BUFFER); return ret; } diff --git a/wolfcrypt/src/port/nxp/se050_port.c b/wolfcrypt/src/port/nxp/se050_port.c index 3a231a77d8..a514ecce7f 100644 --- a/wolfcrypt/src/port/nxp/se050_port.c +++ b/wolfcrypt/src/port/nxp/se050_port.c @@ -738,9 +738,7 @@ int se050_rsa_use_key_id(struct RsaKey* key, word32 keyId) status = kStatus_SSS_Fail; } } - if (derBuf != NULL) { - XFREE(derBuf, key->heap, DYNAMIC_TYPE_TMP_BUFFER); - } + XFREE(derBuf, key->heap, DYNAMIC_TYPE_TMP_BUFFER); if (status == kStatus_SSS_Success) { key->keyId = keyId; @@ -884,9 +882,7 @@ int se050_rsa_create_key(struct RsaKey* key, int size, long e) status = kStatus_SSS_Fail; } } - if (derBuf != NULL) { - XFREE(derBuf, key->heap, DYNAMIC_TYPE_TMP_BUFFER); - } + XFREE(derBuf, key->heap, DYNAMIC_TYPE_TMP_BUFFER); if (status == kStatus_SSS_Success) { key->keyId = keyId; diff --git a/wolfcrypt/src/rsa.c b/wolfcrypt/src/rsa.c index 71745bcbfd..db458df0f9 100644 --- a/wolfcrypt/src/rsa.c +++ b/wolfcrypt/src/rsa.c @@ -373,9 +373,7 @@ int wc_InitRsaHw(RsaKey* key) } /* check for existing mod buffer to avoid memory leak */ - if (key->mod != NULL) { - XFREE(key->mod, key->heap, DYNAMIC_TYPE_KEY); - } + XFREE(key->mod, key->heap, DYNAMIC_TYPE_KEY); key->pubExp = e; key->mod = m; @@ -2144,9 +2142,7 @@ static int wc_RsaFunctionSync(const byte* in, word32 inLen, byte* out, #endif } - if (d != NULL) { - XFREE(d, key->heap, DYNAMIC_TYPE_PRIVATE_KEY); - } + XFREE(d, key->heap, DYNAMIC_TYPE_PRIVATE_KEY); } #endif break; @@ -5085,16 +5081,11 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng) #if !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SE050) #ifdef WOLFSSL_SMALL_STACK - if (p) - XFREE(p, key->heap, DYNAMIC_TYPE_RSA); - if (q) - XFREE(q, key->heap, DYNAMIC_TYPE_RSA); - if (tmp1) - XFREE(tmp1, key->heap, DYNAMIC_TYPE_RSA); - if (tmp2) - XFREE(tmp2, key->heap, DYNAMIC_TYPE_RSA); - if (tmp3) - XFREE(tmp3, key->heap, DYNAMIC_TYPE_RSA); + XFREE(p, key->heap, DYNAMIC_TYPE_RSA); + XFREE(q, key->heap, DYNAMIC_TYPE_RSA); + XFREE(tmp1, key->heap, DYNAMIC_TYPE_RSA); + XFREE(tmp2, key->heap, DYNAMIC_TYPE_RSA); + XFREE(tmp3, key->heap, DYNAMIC_TYPE_RSA); #elif defined(WOLFSSL_CHECK_MEM_ZERO) mp_memzero_check(p); mp_memzero_check(q); diff --git a/wolfcrypt/src/srp.c b/wolfcrypt/src/srp.c index 5216fecf3f..717a93822e 100644 --- a/wolfcrypt/src/srp.c +++ b/wolfcrypt/src/srp.c @@ -903,10 +903,8 @@ int wc_SrpComputeKey(Srp* srp, byte* clientPubKey, word32 clientPubKeySz, } #ifdef WOLFSSL_SMALL_STACK - if (hash) - XFREE(hash, srp->heap, DYNAMIC_TYPE_SRP); - if (digest) - XFREE(digest, srp->heap, DYNAMIC_TYPE_SRP); + XFREE(hash, srp->heap, DYNAMIC_TYPE_SRP); + XFREE(digest, srp->heap, DYNAMIC_TYPE_SRP); if (u) { if (r != WC_NO_ERR_TRACE(MP_INIT_E)) mp_clear(u); diff --git a/wolfcrypt/src/wc_kyber.c b/wolfcrypt/src/wc_kyber.c index a99cd6c1e9..ffa37d84c1 100644 --- a/wolfcrypt/src/wc_kyber.c +++ b/wolfcrypt/src/wc_kyber.c @@ -286,9 +286,7 @@ int wc_KyberKey_MakeKeyWithRandom(KyberKey* key, const unsigned char* rand, } /* Free dynamic memory allocated in function. */ - if (a != NULL) { - XFREE(a, key->heap, DYNAMIC_TYPE_TMP_BUFFER); - } + XFREE(a, key->heap, DYNAMIC_TYPE_TMP_BUFFER); return ret; } @@ -892,9 +890,7 @@ int wc_KyberKey_Decapsulate(KyberKey* key, unsigned char* ss, #ifndef USE_INTEL_SPEEDUP /* Dispose of dynamic memory allocated in function. */ - if (cmp != NULL) { - XFREE(cmp, key->heap, DYNAMIC_TYPE_TMP_BUFFER); - } + XFREE(cmp, key->heap, DYNAMIC_TYPE_TMP_BUFFER); #endif return ret; diff --git a/wolfcrypt/src/wc_pkcs11.c b/wolfcrypt/src/wc_pkcs11.c index 363d90c8da..78d78dc1a9 100644 --- a/wolfcrypt/src/wc_pkcs11.c +++ b/wolfcrypt/src/wc_pkcs11.c @@ -559,9 +559,7 @@ static int Pkcs11Slot_FindByTokenName(Pkcs11Dev* dev, } out: - if (slot != NULL) { - XFREE(slot, dev->heap, DYNAMIC_TYPE_TMP_BUFFER); - } + XFREE(slot, dev->heap, DYNAMIC_TYPE_TMP_BUFFER); return ret; } @@ -629,9 +627,7 @@ static int Pkcs11Token_Init(Pkcs11Token* token, Pkcs11Dev* dev, int slotId, token->userPinLogin = 0; } - if (slot != NULL) { - XFREE(slot, dev->heap, DYNAMIC_TYPE_TMP_BUFFER); - } + XFREE(slot, dev->heap, DYNAMIC_TYPE_TMP_BUFFER); return ret; } @@ -1154,8 +1150,7 @@ static int Pkcs11CreateEccPublicKey(CK_OBJECT_HANDLE* publicKey, } } - if (ecPoint != NULL) - XFREE(ecPoint, public_key->heap, DYNAMIC_TYPE_ECC); + XFREE(ecPoint, public_key->heap, DYNAMIC_TYPE_ECC); return ret; } @@ -1732,10 +1727,8 @@ static int Pkcs11GetRsaPublicKey(RsaKey* key, Pkcs11Session* session, if (ret == 0) ret = wc_RsaPublicKeyDecodeRaw(mod, modSz, exp, expSz, key); - if (exp != NULL) - XFREE(exp, key->heap, DYNAMIC_TYPE_TMP_BUFFER); - if (mod != NULL) - XFREE(mod, key->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(exp, key->heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(mod, key->heap, DYNAMIC_TYPE_TMP_BUFFER); return ret; } @@ -2238,8 +2231,7 @@ static int Pkcs11FindEccKey(CK_OBJECT_HANDLE* key, CK_OBJECT_CLASS keyClass, } } - if (ecPoint != NULL) - XFREE(ecPoint, eccKey->heap, DYNAMIC_TYPE_ECC); + XFREE(ecPoint, eccKey->heap, DYNAMIC_TYPE_ECC); return ret; } @@ -2322,8 +2314,7 @@ static int Pkcs11GetEccPublicKey(ecc_key* key, Pkcs11Session* session, key->type = ECC_PUBLICKEY; } - if (point != NULL) - XFREE(point, key->heap, DYNAMIC_TYPE_ECC); + XFREE(point, key->heap, DYNAMIC_TYPE_ECC); return ret; } diff --git a/wolfcrypt/src/wolfmath.c b/wolfcrypt/src/wolfmath.c index eb5f5419cf..b7853dd8fd 100644 --- a/wolfcrypt/src/wolfmath.c +++ b/wolfcrypt/src/wolfmath.c @@ -358,9 +358,7 @@ void wc_bigint_zero(WC_BIGINT* a) void wc_bigint_free(WC_BIGINT* a) { if (a) { - if (a->buf) { - XFREE(a->buf, a->heap, DYNAMIC_TYPE_WOLF_BIGINT); - } + XFREE(a->buf, a->heap, DYNAMIC_TYPE_WOLF_BIGINT); a->buf = NULL; a->len = 0; }