Fix memory leak in ssh_kex2 function #461
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request addresses a memory leak issue within the
ssh_kex2
function. The function callskex_names_cat
to concatenate key exchange algorithm names, which returns dynamically allocated memory. According to the design ofkex_names_cat
, the caller is responsible for freeing this memory.However, in the original implementation of
ssh_kex2
, the allocated memory bykex_names_cat
(assigned to the pointers
) was not freed before the function returned. This oversight led to a memory leak, as the pointer to the allocated memory was lost upon function exit, with no way to reclaim or free it later.The proposed change introduces a
free(s)
call just before the end of thessh_kex2
function, ensuring that the dynamically allocated memory is correctly deallocated. This change prevents the memory leak, ensuring that all allocated resources withinssh_kex2
are properly managed and released.