Skip to content

Commit 625ea89

Browse files
committed
save heap before Free in Delete wrappers
1 parent f086e91 commit 625ea89

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

wolfcrypt/src/aes.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13661,10 +13661,12 @@ Aes* wc_AesNew_Label(const char* label, void* heap, int devId,
1366113661

1366213662
int wc_AesDelete(Aes *aes, Aes** aes_p)
1366313663
{
13664+
void* heap;
1366413665
if (aes == NULL)
1366513666
return BAD_FUNC_ARG;
13667+
heap = aes->heap;
1366613668
wc_AesFree(aes);
13667-
XFREE(aes, aes->heap, DYNAMIC_TYPE_AES);
13669+
XFREE(aes, heap, DYNAMIC_TYPE_AES);
1366813670
if (aes_p != NULL)
1366913671
*aes_p = NULL;
1367013672
return 0;

wolfcrypt/src/hash.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,12 +866,14 @@ wc_HashAlg* wc_HashNew(enum wc_HashType type, void* heap, int devId,
866866

867867
int wc_HashDelete(wc_HashAlg *hash, wc_HashAlg **hash_p) {
868868
int ret;
869+
void* heap;
869870
if (hash == NULL)
870871
return BAD_FUNC_ARG;
872+
heap = hash->heap;
871873
ret = wc_HashFree(hash, hash->type);
872874
if (ret < 0)
873875
return ret;
874-
XFREE(hash, hash->heap, DYNAMIC_TYPE_HASHES);
876+
XFREE(hash, heap, DYNAMIC_TYPE_HASHES);
875877
if (hash_p != NULL)
876878
*hash_p = NULL;
877879
return 0;

wolfcrypt/src/wc_mlkem.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,12 @@ MlKemKey* wc_MlKemKey_New(int type, void* heap, int devId)
337337

338338
int wc_MlKemKey_Delete(MlKemKey* key, MlKemKey** key_p)
339339
{
340+
void* heap;
340341
if (key == NULL)
341342
return BAD_FUNC_ARG;
343+
heap = key->heap;
342344
wc_MlKemKey_Free(key);
343-
XFREE(key, key->heap, DYNAMIC_TYPE_TMP_BUFFER);
345+
XFREE(key, heap, DYNAMIC_TYPE_TMP_BUFFER);
344346
if (key_p != NULL)
345347
*key_p = NULL;
346348

0 commit comments

Comments
 (0)