Skip to content

Commit 5c900e1

Browse files
committed
Fix memory errors
1 parent 5044ed4 commit 5c900e1

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

tests/api.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3587,7 +3587,7 @@ static int test_wolfSSL_CTX_use_certificate_chain_buffer_format(void)
35873587
wolfSSL_CTX_free(ctx);
35883588
#ifndef NO_FILESYSTEM
35893589
if (buf != NULL) {
3590-
free(buf);
3590+
XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
35913591
}
35923592
#endif
35933593
#endif
@@ -11393,7 +11393,7 @@ static int test_wc_PemToDer(void)
1139311393
pDer = NULL;
1139411394

1139511395
if (cert_buf != NULL) {
11396-
free(cert_buf);
11396+
XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1139711397
cert_buf = NULL;
1139811398
}
1139911399

@@ -11405,7 +11405,7 @@ static int test_wc_PemToDer(void)
1140511405
pDer = NULL;
1140611406

1140711407
if (cert_buf != NULL) {
11408-
free(cert_buf);
11408+
XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1140911409
cert_buf = NULL;
1141011410
}
1141111411

@@ -11427,7 +11427,7 @@ static int test_wc_PemToDer(void)
1142711427
#endif
1142811428
wc_FreeDer(&pDer);
1142911429
if (cert_buf != NULL)
11430-
free(cert_buf);
11430+
XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1143111431
}
1143211432
#endif
1143311433
#endif
@@ -11484,7 +11484,7 @@ static int test_wc_CertPemToDer(void)
1148411484
if (cert_der != NULL)
1148511485
free(cert_der);
1148611486
if (cert_buf != NULL)
11487-
free(cert_buf);
11487+
XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1148811488
#endif
1148911489
return EXPECT_RESULT();
1149011490
}
@@ -11598,7 +11598,7 @@ static int test_wc_PubKeyPemToDer(void)
1159811598
}
1159911599

1160011600
if (cert_buf != NULL) {
11601-
free(cert_buf);
11601+
XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1160211602
}
1160311603
#endif
1160411604
return EXPECT_RESULT();
@@ -11987,7 +11987,7 @@ static int test_wc_CheckCertSigPubKey(void)
1198711987
if (cert_der != NULL)
1198811988
free(cert_der);
1198911989
if (cert_buf != NULL)
11990-
free(cert_buf);
11990+
XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1199111991
#endif
1199211992
return EXPECT_RESULT();
1199311993
}
@@ -20790,9 +20790,9 @@ static int test_RsaSigFailure_cm(void)
2079020790
#endif
2079120791
}
2079220792

20793-
/* load_file() uses malloc. */
20793+
/* load_file() uses XMALLOC. */
2079420794
if (cert_buf != NULL) {
20795-
free(cert_buf);
20795+
XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
2079620796
}
2079720797
#endif /* !NO_RSA */
2079820798
return EXPECT_RESULT();
@@ -20831,9 +20831,9 @@ static int test_EccSigFailure_cm(void)
2083120831
#endif
2083220832
}
2083320833

20834-
/* load_file() uses malloc. */
20834+
/* load_file() uses XMALLOC. */
2083520835
if (cert_buf != NULL) {
20836-
free(cert_buf);
20836+
XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
2083720837
}
2083820838
#ifdef FP_ECC
2083920839
wc_ecc_fp_free();
@@ -25244,7 +25244,7 @@ static int load_pem_key_file_as_der(const char* privKeyFile, DerBuffer** pDer,
2524425244
}
2524525245

2524625246
if (key_buf != NULL) {
25247-
free(key_buf); key_buf = NULL;
25247+
XFREE(key_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER); key_buf = NULL;
2524825248
}
2524925249
(void)encInfo; /* not used in this test */
2525025250

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)