Skip to content

Schannel: plug a memory-leak#6457

Closed
gvanem wants to merge 1 commit into
masterfrom
schannel-leak
Closed

Schannel: plug a memory-leak#6457
gvanem wants to merge 1 commit into
masterfrom
schannel-leak

Conversation

@gvanem

@gvanem gvanem commented Jan 14, 2021

Copy link
Copy Markdown
Contributor

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?

@bagder bagder left a comment

Copy link
Copy Markdown
Member

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

bagder commented Jan 14, 2021

Copy link
Copy Markdown
Member

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

@bagder

bagder commented Jan 14, 2021

Copy link
Copy Markdown
Member

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

@gvanem

gvanem commented Jan 14, 2021

Copy link
Copy Markdown
Contributor Author

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

bagder commented Jan 14, 2021

Copy link
Copy Markdown
Member

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.

3 participants