Skip to content

wincng: fix another resource leak in ssh2_ecdh_gen_k() - #2299

Closed
vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:wcng1
Closed

vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:wcng1

Conversation

@vszakats

Copy link
Copy Markdown
Member

"In ssh2_ecdh_gen_k, agreed_secret_handle is only destroyed when
result != LIBSSH2_ERROR_NONE. On the success path, the handle is never
passed to BCryptDestroySecret, causing a resource leak. The handle
should be destroyed unconditionally in the cleanup block, regardless of
success or failure."

Ref: 2f7f107 #2038
Follow-up to 3e72343 #1315

"In `ssh2_ecdh_gen_k`, `agreed_secret_handle` is only destroyed when
`result != LIBSSH2_ERROR_NONE`. On the success path, the handle is never
passed to `BCryptDestroySecret`, causing a resource leak. The handle
should be destroyed unconditionally in the cleanup block, regardless of
success or failure."

Ref: 2f7f107 libssh2#2038
Follow-up to 3e72343 libssh2#1315

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a WinCNG resource leak in ssh2_ecdh_gen_k() by ensuring the ECDH agreed secret handle is destroyed on both success and failure paths, aligning the cleanup behavior with expected WinCNG handle lifecycle management.

Changes:

  • Always call BCryptDestroySecret(agreed_secret_handle) in the cleanup block when the handle is non-NULL (independent of result).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vszakats vszakats closed this in f2751aa Jul 14, 2026
@vszakats
vszakats deleted the wcng1 branch July 14, 2026 03:28
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.

2 participants