https: fix memory leak with https.request()
Checklist
-
make -j4 test
(UNIX), orvcbuild test nosign
(Windows) passes -
tests and/or benchmarks are included -
commit message follows commit guidelines
Affected core subsystem(s)
https
Description of change
If calling https.request()
with options.headers.host
defined and options.servername
undefined, https.Agent.createSocket
mutates connection options
after https.Agent.addRequest
has created empty socket pool array with mismatching connection name.
This results in two socket pool arrays being created and only the last one gets eventually deleted by removeSocket
- effectively causing a memory leak.
This commit fixes the leak by making sure that addRequest
does the same modifications to options
object as the createSocket
.
createSocket
is intentionally left unmodified to prevent userland regressions.
Test case included.
Fixes: https://github.com/nodejs/node/issues/6687
/cc @nodejs/http @nodejs/crypto