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?

gvanem referenced this pull request Jan 14, 2021
Bug: 8ab78f7#commitcomment-45445950
Reported-by: Gisle Vanem
Closes #6381
@bagder
bagder approved these changes Jan 14, 2021
Copy link
Member

@bagder bagder left a comment

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 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 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 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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants