Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schannel: plug a memory-leak #6457

Closed
wants to merge 1 commit into from
Closed

Schannel: plug a memory-leak #6457

wants to merge 1 commit into from

Conversation

gvanem
Copy link
Contributor

@gvanem gvanem commented Jan 14, 2021

Building with DEBUGBUILD and issuing these commands:

c:\> set CURL_SSL_BACKEND=schannel
c:\> curl.exe https://www.vg.no > NUL
c:\> perl tests\memanalyze.pl \gv\tmp\memdebug.curl

This tool reports:

Leak detected: memory still allocated: 379 bytes
At d354420, there's 379 bytes.
 allocated by vtls/schannel_verify.c:446

I did not build with -DUNICODE. Hence that curlx_unicodefree(cert_hostname_buff) was a no-op and
responsible for the leak. Surely it should be free()'d regardless of -DUNICODE. No?

Copy link
Member

@bagder bagder left a comment

Choose a reason for hiding this comment

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

I think curlx_unicodefree() should only really be used if the variable doesn't exist in non-unicode builds because calling free() on a NULL pointer is defined and safe.

@bagder
Copy link
Member

bagder commented Jan 14, 2021

Hm not even that, because the macro assigns the variable to NULL in non-unicode... Can't we remove the macro completely?

@bagder
Copy link
Member

bagder commented Jan 14, 2021

No: because in non-unicode builds it is used for (or rather should be used for) pointing to data that isn't allocated.

@gvanem
Copy link
Contributor Author

gvanem commented Jan 14, 2021

Speaking of such macros; it's IMHO more evident it's a macro if it was defined and used as CURLX_UNICODEFREE(ptr).
Just my ¥ 0.2.

@bagder
Copy link
Member

bagder commented Jan 14, 2021

I agree

bagder added a commit that referenced this pull request Jan 14, 2021
CURLX_UNICODEFREE() is the name now to make it more obvious to users
that this is a macro and not a plain or pretend-to-be function call.

Suggested-by: Gisle Vanem
Ref: #6457
@bagder bagder closed this in e87ad71 Jan 14, 2021
@bagder bagder deleted the schannel-leak branch March 7, 2023 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants