Skip to content

Commit

Permalink
free temporary buffer after use
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobBarthelmeh committed Jan 27, 2025
1 parent d2cbff7 commit c40d19b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/sign-verify/clu_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,9 +659,9 @@ int wolfCLU_sign_data_dilithium (byte* data, char* out, word32 dataSz, char* pri

/* retrieving private key and staoring in the Dilithium key */
ret = wc_Dilithium_PrivateKeyDecode(privBuf, &index, key, privBufSz);
XFREE(privBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (ret != 0) {
wolfCLU_LogError("Failed to decode private key.\nRET: %d", ret);
XFREE(privBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
wc_FreeRng(&rng);
#ifdef WOLFSSL_SMALL_STACK
wc_dilithium_free(key);
Expand All @@ -680,7 +680,7 @@ int wolfCLU_sign_data_dilithium (byte* data, char* out, word32 dataSz, char* pri
#endif
return MEMORY_E;
}

/* sign the message usign Dilithium private key */
ret = wc_dilithium_sign_msg(data, dataSz, outBuf, &outBufSz, key, &rng);
if (ret != 0) {
Expand All @@ -701,9 +701,10 @@ int wolfCLU_sign_data_dilithium (byte* data, char* out, word32 dataSz, char* pri

XFREE(outBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
wc_FreeRng(&rng);
wc_dilithium_free(key);

#ifdef WOLFSSL_SMALL_STACK
wc_dilithium_free(key);
XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
#endif

return WOLFCLU_SUCCESS;
Expand Down

0 comments on commit c40d19b

Please sign in to comment.