Closed earlephilhower closed 7 years ago
Thank you for the PR, @earlephilhower!
Until this version 425067abe69606ab7002b34c047e46a007f29895 ssl_ext_free
for freeing correctly the data, but then the free-ing issue was introduced in 2213f304490e059d72fd511cd6548b23a685ee8f. Glad that someone noticed it.
The current fix though relies on the fact that host-name will always be set free(ssl_ext->host_name); . Which is a wrong assumption. I would prefer to have the original code from 425067abe69606ab7002b34c047e46a007f29895 which is:
if (ssl_ext->host_name != NULL)
{
free(ssl_ext->host_name);
}
@slaff freeing aan null pointer is perfectly legal in cpp and has no effect
@slaff freeing aan null pointer is perfectly legal in cpp and has no effect
Yep, that is fine but axTLS can be used in C context. IMHO it would be better if we have code that works well on C and C++.
@slaff same is true for ansi c: if ptr is a null pointer, no action occurs :)
@Jeroen88 is right, passing NULL to free
should be a no-op, if this is not the case it is a bug in implementation of free
on a given platform. Some coding standards explicitly discourage checking a pointer for the single purpose of freeing it.
@igrr @Jeroen88 Thanks for pointing that out. I will have to brush up my dusty C/C++ skills.
@Jeroen88 found a memory leak in axtls where the new ext_host_name pointer was leaking on every SSL reconnection, eventually eating up all RAM and crashing the chip (see esp8266/Arduino#3428 ).
This 1-line patch just frees the allocated hostname in during the ssl_ext_free call, eliminating the leakage.