diff options
author | Ilkka Myller <ilkka.myller@nodefield.com> | 2016-09-18 14:34:48 +0300 |
---|---|---|
committer | Ilkka Myller <ilkka.myller@nodefield.com> | 2016-09-21 03:22:15 +0300 |
commit | db5a8791fac4d7e088114488f9f5fda4c660ed5a (patch) | |
tree | 7e09e984233c6fbe6d673470458de7ef8cab96ba /lib/_http_agent.js | |
parent | c5ce7f4d9e36fc9f06547de1e41cdf4b2ac02720 (diff) | |
download | android-node-v8-db5a8791fac4d7e088114488f9f5fda4c660ed5a.tar.gz android-node-v8-db5a8791fac4d7e088114488f9f5fda4c660ed5a.tar.bz2 android-node-v8-db5a8791fac4d7e088114488f9f5fda4c660ed5a.zip |
https: fix memory leak with https.request()
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` - 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.
PR-URL: https://github.com/nodejs/node/pull/8647
Fixes: https://github.com/nodejs/node/issues/6687
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jackson Tian <shvyo1987@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/_http_agent.js')
-rw-r--r-- | lib/_http_agent.js | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/_http_agent.js b/lib/_http_agent.js index bac10c4dab..6ea801c3ed 100644 --- a/lib/_http_agent.js +++ b/lib/_http_agent.js @@ -123,6 +123,14 @@ Agent.prototype.addRequest = function(req, options) { options = util._extend({}, options); options = util._extend(options, this.options); + if (!options.servername) { + options.servername = options.host; + const hostHeader = req.getHeader('host'); + if (hostHeader) { + options.servername = hostHeader.replace(/:.*$/, ''); + } + } + var name = this.getName(options); if (!this.sockets[name]) { this.sockets[name] = []; |