Skip to content

Fix memory leak in hkdf_expand#5

Open
joerowell wants to merge 1 commit into
n-for-1-auth:mainfrom
joerowell:main
Open

Fix memory leak in hkdf_expand#5
joerowell wants to merge 1 commit into
n-for-1-auth:mainfrom
joerowell:main

Conversation

@joerowell

@joerowell joerowell commented Nov 15, 2022

Copy link
Copy Markdown

At the moment hkdf_expand allocates memory on each iteration of the loop but never frees it:

for(int i = 1; i <= N; i++) {
    auto input = new block[8 + info_len + cur_T_len];
    ...
}

This means that the program leaks memory each time hkdf_expand is called.

This PR fixes this by:

  1. Moving the allocation outside of the loop. This should also make the code run faster.
  2. Freeing the memory after the loop terminates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant