Skip to content

Commit 94b6b1e

Browse files
committed
Fix memory errors
1 parent 9980a6b commit 94b6b1e

3 files changed

Lines changed: 21 additions & 21 deletions

File tree

tests/api.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3588,7 +3588,7 @@ static int test_wolfSSL_CTX_use_certificate_chain_buffer_format(void)
35883588
wolfSSL_CTX_free(ctx);
35893589
#ifndef NO_FILESYSTEM
35903590
if (buf != NULL) {
3591-
free(buf);
3591+
XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
35923592
}
35933593
#endif
35943594
#endif
@@ -11400,7 +11400,7 @@ static int test_wc_PemToDer(void)
1140011400
pDer = NULL;
1140111401

1140211402
if (cert_buf != NULL) {
11403-
free(cert_buf);
11403+
XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1140411404
cert_buf = NULL;
1140511405
}
1140611406

@@ -11412,7 +11412,7 @@ static int test_wc_PemToDer(void)
1141211412
pDer = NULL;
1141311413

1141411414
if (cert_buf != NULL) {
11415-
free(cert_buf);
11415+
XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1141611416
cert_buf = NULL;
1141711417
}
1141811418

@@ -11434,7 +11434,7 @@ static int test_wc_PemToDer(void)
1143411434
#endif
1143511435
wc_FreeDer(&pDer);
1143611436
if (cert_buf != NULL)
11437-
free(cert_buf);
11437+
XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1143811438
}
1143911439
#endif
1144011440
#endif
@@ -11491,7 +11491,7 @@ static int test_wc_CertPemToDer(void)
1149111491
if (cert_der != NULL)
1149211492
free(cert_der);
1149311493
if (cert_buf != NULL)
11494-
free(cert_buf);
11494+
XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1149511495
#endif
1149611496
return EXPECT_RESULT();
1149711497
}
@@ -11605,7 +11605,7 @@ static int test_wc_PubKeyPemToDer(void)
1160511605
}
1160611606

1160711607
if (cert_buf != NULL) {
11608-
free(cert_buf);
11608+
XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1160911609
}
1161011610
#endif
1161111611
return EXPECT_RESULT();
@@ -11994,7 +11994,7 @@ static int test_wc_CheckCertSigPubKey(void)
1199411994
if (cert_der != NULL)
1199511995
free(cert_der);
1199611996
if (cert_buf != NULL)
11997-
free(cert_buf);
11997+
XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1199811998
#endif
1199911999
return EXPECT_RESULT();
1200012000
}
@@ -20797,9 +20797,9 @@ static int test_RsaSigFailure_cm(void)
2079720797
#endif
2079820798
}
2079920799

20800-
/* load_file() uses malloc. */
20800+
/* load_file() uses XMALLOC. */
2080120801
if (cert_buf != NULL) {
20802-
free(cert_buf);
20802+
XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
2080320803
}
2080420804
#endif /* !NO_RSA */
2080520805
return EXPECT_RESULT();
@@ -20838,9 +20838,9 @@ static int test_EccSigFailure_cm(void)
2083820838
#endif
2083920839
}
2084020840

20841-
/* load_file() uses malloc. */
20841+
/* load_file() uses XMALLOC. */
2084220842
if (cert_buf != NULL) {
20843-
free(cert_buf);
20843+
XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
2084420844
}
2084520845
#ifdef FP_ECC
2084620846
wc_ecc_fp_free();
@@ -25251,7 +25251,7 @@ static int load_pem_key_file_as_der(const char* privKeyFile, DerBuffer** pDer,
2525125251
}
2525225252

2525325253
if (key_buf != NULL) {
25254-
free(key_buf); key_buf = NULL;
25254+
XFREE(key_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER); key_buf = NULL;
2525525255
}
2525625256
(void)encInfo; /* not used in this test */
2525725257

tests/api/test_certman.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ static int test_cm_load_ca_file(const char* ca_cert_file)
269269

270270
if (ret == WOLFSSL_SUCCESS) {
271271
/* test including null terminator in length */
272-
byte* tmp = (byte*)realloc(cert_buf, cert_sz+1);
272+
byte* tmp = (byte*)XREALLOC(cert_buf, cert_sz+1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
273273
if (tmp == NULL) {
274274
ret = MEMORY_E;
275275
}
@@ -297,7 +297,7 @@ static int test_cm_load_ca_file(const char* ca_cert_file)
297297
#endif
298298

299299
}
300-
free(cert_buf);
300+
XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
301301

302302
return ret;
303303
}
@@ -339,7 +339,7 @@ static int test_cm_load_ca_file_ex(const char* ca_cert_file, word32 flags)
339339

340340
if (ret == WOLFSSL_SUCCESS) {
341341
/* test including null terminator in length */
342-
byte* tmp = (byte*)realloc(cert_buf, cert_sz+1);
342+
byte* tmp = (byte*)XREALLOC(cert_buf, cert_sz+1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
343343
if (tmp == NULL) {
344344
ret = MEMORY_E;
345345
}
@@ -367,7 +367,7 @@ static int test_cm_load_ca_file_ex(const char* ca_cert_file, word32 flags)
367367
#endif
368368

369369
}
370-
free(cert_buf);
370+
XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
371371

372372
return ret;
373373
}
@@ -614,13 +614,13 @@ int test_wolfSSL_CertManagerLoadCABufferType(void)
614614
if (cm)
615615
wolfSSL_CertManagerFree(cm);
616616
if (ca_cert_buf)
617-
free(ca_cert_buf);
617+
XFREE(ca_cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
618618
if (int1_cert_buf)
619-
free(int1_cert_buf);
619+
XFREE(int1_cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
620620
if (int2_cert_buf)
621-
free(int2_cert_buf);
621+
XFREE(int2_cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
622622
if (client_cert_buf)
623-
free(client_cert_buf);
623+
XFREE(client_cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
624624
#endif
625625

626626
return EXPECT_RESULT();

wolfcrypt/src/memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ void wc_MemZero_Check(void* addr, size_t len)
313313
nextIdx--;
314314
if (nextIdx > 0) {
315315
/* Remove entry. */
316-
XMEMCPY(memZero + i, memZero + i + 1,
316+
XMEMMOVE(memZero + i, memZero + i + 1,
317317
sizeof(MemZero) * (nextIdx - i));
318318
/* Clear out top to make it easier to see what is to be checked. */
319319
XMEMSET(&memZero[nextIdx], 0, sizeof(MemZero));

0 commit comments

Comments
 (0)