Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No if xfree #7839

Merged
merged 12 commits into from
Aug 7, 2024
12 changes: 3 additions & 9 deletions IDE/Renesas/e2studio/RA6M4/test/src/test_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,11 @@ void Clr_CallbackCtx(FSPSM_ST *g)
(void) g;

#if defined(WOLFSSL_RENESAS_SCEPROTECT_CRYPTONLY)
if (g->wrapped_key_rsapri2048 != NULL)
XFREE(g->wrapped_key_rsapri2048,
NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(g->wrapped_key_rsapri2048, NULL, DYNAMIC_TYPE_TMP_BUFFER);

if (g->wrapped_key_rsapub2048 != NULL)
XFREE(g->wrapped_key_rsapub2048,
NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(g->wrapped_key_rsapub2048, NULL, DYNAMIC_TYPE_TMP_BUFFER);

if (g->wrapped_key_rsapri1024 != NULL)
XFREE(g->wrapped_key_rsapri1024,
NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(g->wrapped_key_rsapri1024, NULL, DYNAMIC_TYPE_TMP_BUFFER);

if (g->wrapped_key_rsapub2048 != NULL)
XFREE(g->wrapped_key_rsapub1024,
Expand Down
28 changes: 7 additions & 21 deletions IDE/Renesas/e2studio/RA6M4/test/src/wolfssl_sce_unit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,18 +691,10 @@ static int sce_rsa_test(int prnt, int keySize)
wc_FreeRsaKey(key);
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
if (in != NULL) {
XFREE(in, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
if (in2 != NULL) {
XFREE(in2, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
if (out != NULL) {
XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
if (out2 != NULL) {
XFREE(out2, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
XFREE(in, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(in2, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(out2, NULL, DYNAMIC_TYPE_TMP_BUFFER);

return ret;
}
Expand Down Expand Up @@ -778,15 +770,9 @@ static int sce_rsa_SignVerify_test(int prnt, int keySize)
wc_FreeRsaKey(key);
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
if (in != NULL) {
XFREE(in, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
if (in2 != NULL) {
XFREE(in2, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
if (out != NULL) {
XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
XFREE(in, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(in2, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);

return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,13 @@ typedef struct tagInfo

void Clr_CallbackCtx(TsipUserCtx *g)
{
if (g->rsa1024pri_keyIdx != NULL)
XFREE(g->rsa1024pri_keyIdx,
NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(g->rsa1024pri_keyIdx, NULL, DYNAMIC_TYPE_TMP_BUFFER);

if (g->rsa1024pub_keyIdx != NULL)
XFREE(g->rsa1024pub_keyIdx,
NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(g->rsa1024pub_keyIdx, NULL, DYNAMIC_TYPE_TMP_BUFFER);

if (g->rsa2048pri_keyIdx != NULL)
XFREE(g->rsa2048pri_keyIdx,
NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(g->rsa2048pri_keyIdx, NULL, DYNAMIC_TYPE_TMP_BUFFER);

if (g->rsa2048pub_keyIdx != NULL)
XFREE(g->rsa2048pub_keyIdx,
NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(g->rsa2048pub_keyIdx, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XMEMSET(g, 0, sizeof(TsipUserCtx));
}

Expand Down Expand Up @@ -789,15 +781,9 @@ static int tsip_rsa_SignVerify_test(int prnt, int keySize)
wc_FreeRsaKey(key);
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
if (in != NULL) {
XFREE(in, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
if (in2 != NULL) {
XFREE(in2, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
if (out != NULL) {
XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
XFREE(in, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(in2, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);

return ret;
}
Expand Down
28 changes: 7 additions & 21 deletions IDE/Renesas/e2studio/RZN2L/test/src/test/wolfssl_rsip_unit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,18 +718,10 @@ static int rsip_rsa_test(int prnt, int keySize)
wc_FreeRsaKey(key);
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
if (in != NULL) {
XFREE(in, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
if (in2 != NULL) {
XFREE(in2, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
if (out != NULL) {
XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
if (out2 != NULL) {
XFREE(out2, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
XFREE(in, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(in2, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(out2, NULL, DYNAMIC_TYPE_TMP_BUFFER);

(void) prnt;
return ret;
Expand Down Expand Up @@ -808,15 +800,9 @@ static int rsip_rsa_SignVerify_test(int prnt, int keySize)
wc_FreeRsaKey(key);
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
if (in != NULL) {
XFREE(in, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
if (in2 != NULL) {
XFREE(in2, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
if (out != NULL) {
XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
XFREE(in, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(in2, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);

return ret;
}
Expand Down
8 changes: 2 additions & 6 deletions IDE/STM32Cube/wolfssl_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -1700,9 +1700,7 @@ static int tls13_uart_server(void)
}

#ifdef WOLFSSL_SMALL_STACK
if (tbuf != NULL) {
XFREE(tbuf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
XFREE(tbuf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif

return ret;
Expand Down Expand Up @@ -1795,9 +1793,7 @@ static int tls13_uart_client(void)
wolfSSL_CTX_free(ctx);
}
#ifdef WOLFSSL_SMALL_STACK
if (tbuf != NULL) {
XFREE(tbuf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
XFREE(tbuf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif

return ret;
Expand Down
6 changes: 2 additions & 4 deletions examples/server/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -3533,10 +3533,8 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)

size = wolfSSL_get_server_random(ssl, rnd, size);
if (size == 0) {
if (rnd) {
XFREE(rnd, NULL, DYNAMIC_TYPE_TMP_BUFFER);
rnd = NULL;
}
XFREE(rnd, NULL, DYNAMIC_TYPE_TMP_BUFFER);
rnd = NULL;
err_sys_ex(runWithErrors, "error getting server random buffer");
}

Expand Down
49 changes: 16 additions & 33 deletions linuxkm/lkcapi_glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -2451,34 +2451,25 @@ static int aes_xts_128_test(void)

test_xts_end:

if (enc2)
XFREE(enc2, NULL, DYNAMIC_TYPE_AES);
if (dec2)
XFREE(dec2, NULL, DYNAMIC_TYPE_AES);
if (src)
XFREE(src, NULL, DYNAMIC_TYPE_AES);
if (dst)
XFREE(dst, NULL, DYNAMIC_TYPE_AES);
XFREE(enc2, NULL, DYNAMIC_TYPE_AES);
XFREE(dec2, NULL, DYNAMIC_TYPE_AES);
XFREE(src, NULL, DYNAMIC_TYPE_AES);
XFREE(dst, NULL, DYNAMIC_TYPE_AES);
if (req)
skcipher_request_free(req);
if (tfm)
crypto_free_skcipher(tfm);

out:

if (large_input)
XFREE(large_input, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(large_input, NULL, DYNAMIC_TYPE_TMP_BUFFER);

if (aes_inited)
wc_AesXtsFree(aes);

if (buf)
XFREE(buf, NULL, DYNAMIC_TYPE_AES);
if (cipher)
XFREE(cipher, NULL, DYNAMIC_TYPE_AES);

if (aes)
XFREE(aes, NULL, DYNAMIC_TYPE_AES);
XFREE(buf, NULL, DYNAMIC_TYPE_AES);
XFREE(cipher, NULL, DYNAMIC_TYPE_AES);
XFREE(aes, NULL, DYNAMIC_TYPE_AES);

#undef AES_XTS_128_TEST_BUF_SIZ

Expand Down Expand Up @@ -2939,34 +2930,26 @@ static int aes_xts_256_test(void)

test_xts_end:

if (enc2)
XFREE(enc2, NULL, DYNAMIC_TYPE_AES);
if (dec2)
XFREE(dec2, NULL, DYNAMIC_TYPE_AES);
if (src)
XFREE(src, NULL, DYNAMIC_TYPE_AES);
if (dst)
XFREE(dst, NULL, DYNAMIC_TYPE_AES);
XFREE(enc2, NULL, DYNAMIC_TYPE_AES);
XFREE(dec2, NULL, DYNAMIC_TYPE_AES);
XFREE(src, NULL, DYNAMIC_TYPE_AES);
XFREE(dst, NULL, DYNAMIC_TYPE_AES);
if (req)
skcipher_request_free(req);
if (tfm)
crypto_free_skcipher(tfm);

out:

if (large_input)
XFREE(large_input, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(large_input, NULL, DYNAMIC_TYPE_TMP_BUFFER);

if (aes_inited)
wc_AesXtsFree(aes);

if (buf)
XFREE(buf, NULL, DYNAMIC_TYPE_AES);
if (cipher)
XFREE(cipher, NULL, DYNAMIC_TYPE_AES);
XFREE(buf, NULL, DYNAMIC_TYPE_AES);
XFREE(cipher, NULL, DYNAMIC_TYPE_AES);

if (aes)
XFREE(aes, NULL, DYNAMIC_TYPE_AES);
XFREE(aes, NULL, DYNAMIC_TYPE_AES);

#undef AES_XTS_256_TEST_BUF_SIZ

Expand Down
15 changes: 5 additions & 10 deletions linuxkm/module_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -803,16 +803,11 @@ static int updateFipsHash(void)

if (tfm != NULL)
crypto_free_shash(tfm);
if (desc != NULL)
XFREE(desc, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (hash != NULL)
XFREE(hash, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (base16_hash != NULL)
XFREE(base16_hash, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (binCoreKey != NULL)
XFREE(binCoreKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (binVerify != NULL)
XFREE(binVerify, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(desc, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(hash, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(base16_hash, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(binCoreKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(binVerify, NULL, DYNAMIC_TYPE_TMP_BUFFER);

return ret;
}
Expand Down
8 changes: 2 additions & 6 deletions src/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 5 additions & 11 deletions src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ WOLFSSL_TXT_DB *wolfSSL_TXT_DB_read(WOLFSSL_BIO *in, int num)
wolfSSL_TXT_DB_free(ret);
ret = NULL;
}
if (buf) {
XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}

Expand Down Expand Up @@ -793,8 +791,7 @@ static char* expandValue(WOLFSSL_CONF *conf, const char* section,
return ret ? ret : str;

expand_cleanup:
if (ret)
XFREE(ret, NULL, DYNAMIC_TYPE_OPENSSL);
XFREE(ret, NULL, DYNAMIC_TYPE_OPENSSL);
return NULL;
}

Expand Down Expand Up @@ -961,8 +958,7 @@ int wolfSSL_NCONF_load(WOLFSSL_CONF *conf, const char *file, long *eline)
cleanup:
if (in)
wolfSSL_BIO_free(in);
if (buf)
XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (eline)
*eline = line;
return ret;
Expand All @@ -986,13 +982,11 @@ void wolfSSL_X509V3_conf_free(WOLFSSL_CONF_VALUE *val)
if (val->name) {
/* Not a section. Don't free section as it is a shared pointer. */
XFREE(val->name, NULL, DYNAMIC_TYPE_OPENSSL);
if (val->value)
XFREE(val->value, NULL, DYNAMIC_TYPE_OPENSSL);
XFREE(val->value, NULL, DYNAMIC_TYPE_OPENSSL);
}
else {
/* Section so val->value is a stack */
if (val->section)
XFREE(val->section, NULL, DYNAMIC_TYPE_OPENSSL);
XFREE(val->section, NULL, DYNAMIC_TYPE_OPENSSL);
/* Only free the stack structures. The contained conf values
* will be freed in wolfSSL_NCONF_free */
sk = (WOLF_STACK_OF(WOLFSSL_CONF_VALUE)*)val->value;
Expand Down
9 changes: 3 additions & 6 deletions src/crl.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,10 @@ static void CRL_Entry_free(CRL_Entry* crle, void* heap)
tmp = next;
}
#endif
if (crle->signature != NULL)
XFREE(crle->signature, heap, DYNAMIC_TYPE_CRL_ENTRY);
if (crle->toBeSigned != NULL)
XFREE(crle->toBeSigned, heap, DYNAMIC_TYPE_CRL_ENTRY);
XFREE(crle->signature, heap, DYNAMIC_TYPE_CRL_ENTRY);
XFREE(crle->toBeSigned, heap, DYNAMIC_TYPE_CRL_ENTRY);
#ifdef WC_RSA_PSS
if (crle->sigParams != NULL)
XFREE(crle->sigParams, heap, DYNAMIC_TYPE_CRL_ENTRY);
XFREE(crle->sigParams, heap, DYNAMIC_TYPE_CRL_ENTRY);
#endif
#if defined(OPENSSL_EXTRA)
if (crle->issuer != NULL) {
Expand Down
Loading