Skip to content

Fix memory leak of CredHandle in wintls.c#803

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-memory-leak-issue
Draft

Fix memory leak of CredHandle in wintls.c#803
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-memory-leak-issue

Conversation

Copy link

Copilot AI commented Feb 28, 2026

hssl_ctx_init allocates a CredHandle via malloc but hssl_ctx_free only calls FreeCredentialsHandle without freeing the backing memory.

  • Added free(ssl_ctx) after FreeCredentialsHandle in hssl_ctx_free
void hssl_ctx_free(hssl_ctx_t ssl_ctx)
{
    SECURITY_STATUS sec_status = FreeCredentialsHandle(ssl_ctx);
    if (sec_status != SEC_E_OK) {
        printe("free_cred_handle FreeCredentialsHandle %d\n", sec_status);
    }
    free(ssl_ctx);
}
Original prompt

This section details on the original issue you should resolve

<issue_title>疑似内存泄漏</issue_title>
<issue_description>首先感谢作者开源了这么好的一个库,使用过程中发现好像有个内存泄漏的地方.麻烦看看
https://github.com/ithewei/libhv/blob/master/ssl/wintls.c#L160

    hCred = (CredHandle*)malloc(sizeof(CredHandle));
    if (hCred == NULL) {
        return NULL;
    }

这里malloc了一个CredHandle* hCred 在 hssl_ctx_free 中好像没有free
https://github.com/ithewei/libhv/blob/master/ssl/wintls.c#L183

void hssl_ctx_free(hssl_ctx_t ssl_ctx)
{
    SECURITY_STATUS sec_status = FreeCredentialsHandle(ssl_ctx);
    if (sec_status != SEC_E_OK) {
        printe("free_cred_handle FreeCredentialsHandle %d\n", sec_status);
    }
}

这应该会导致内存泄漏吧</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 28, 2026 07:44
Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com>
Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix potential memory leak in hssl_ctx_free function Fix memory leak of CredHandle in wintls.c Feb 28, 2026
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