summaryrefslogtreecommitdiff
path: root/lib/readline.js
diff options
context:
space:
mode:
authorYazhong Liu <yorkiefixer@gmail.com>2014-05-08 00:05:39 +0800
committerTrevor Norris <trev.norris@gmail.com>2014-05-12 14:13:14 -0700
commite1aa066fe16e5feb2d5621ce0d2163703da1110c (patch)
tree19e6106f6fb3d7a3189a78e7f658773ca2ac1fba /lib/readline.js
parent0f503cf0de8d43d1f4218dea25534a1cfac88266 (diff)
downloadnodejs-e1aa066fe16e5feb2d5621ce0d2163703da1110c.tar.gz
nodejs-e1aa066fe16e5feb2d5621ce0d2163703da1110c.tar.bz2
nodejs-e1aa066fe16e5feb2d5621ce0d2163703da1110c.zip
readline: fix close event of readline.Interface()
Not removing 'end' listeners for input and output on the 'close' event resulted in an EventEmitter related memory leak. This issue also might be reproduced at: https://github.com/npm/npm/issues/5203 Signed-off-by: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'lib/readline.js')
-rw-r--r--lib/readline.js14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/readline.js b/lib/readline.js
index 1fa217ccd..19ef759fb 100644
--- a/lib/readline.js
+++ b/lib/readline.js
@@ -97,6 +97,13 @@ function Interface(input, output, completer, terminal) {
self.close();
}
+ function ontermend() {
+ if (util.isString(self.line) && self.line.length > 0) {
+ self.emit('line', self.line);
+ }
+ self.close();
+ }
+
function onkeypress(s, key) {
self._ttyWrite(s, key);
}
@@ -121,11 +128,7 @@ function Interface(input, output, completer, terminal) {
// input usually refers to stdin
input.on('keypress', onkeypress);
- input.on('end', function inputEnd() {
- if (util.isString(self.line) && self.line.length > 0)
- self.emit('line', self.line);
- self.close();
- });
+ input.on('end', ontermend);
// Current line
this.line = '';
@@ -142,6 +145,7 @@ function Interface(input, output, completer, terminal) {
output.on('resize', onresize);
self.once('close', function() {
input.removeListener('keypress', onkeypress);
+ input.removeListener('end', ontermend);
output.removeListener('resize', onresize);
});
}