From 8b463cd3adb9e32edba86d6cb552a126708082fe Mon Sep 17 00:00:00 2001 From: Sangmin Yoon Date: Wed, 22 Apr 2015 15:26:44 +0900 Subject: [PATCH] fix history file descriptor leak --- lib/coffee-script/repl.js | 3 ++- src/repl.coffee | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/coffee-script/repl.js b/lib/coffee-script/repl.js index 14e5ab6d..6d9d5106 100644 --- a/lib/coffee-script/repl.js +++ b/lib/coffee-script/repl.js @@ -125,6 +125,7 @@ readFd = fs.openSync(filename, 'r'); buffer = new Buffer(size); fs.readSync(readFd, buffer, 0, size, stat.size - size); + fs.close(readFd); repl.rli.history = buffer.toString().split('\n').reverse(); if (stat.size > maxSize) { repl.rli.history.pop(); @@ -142,7 +143,7 @@ return lastLine = code; } }); - repl.rli.on('exit', function() { + repl.on('exit', function() { return fs.close(fd); }); return repl.commands[getCommandId(repl, 'history')] = { diff --git a/src/repl.coffee b/src/repl.coffee index 7c859fb9..50acf7d1 100644 --- a/src/repl.coffee +++ b/src/repl.coffee @@ -108,6 +108,7 @@ addHistory = (repl, filename, maxSize) -> readFd = fs.openSync filename, 'r' buffer = new Buffer(size) fs.readSync readFd, buffer, 0, size, stat.size - size + fs.close readFd # Set the history on the interpreter repl.rli.history = buffer.toString().split('\n').reverse() # If the history file was truncated we should pop off a potential partial line @@ -125,7 +126,7 @@ addHistory = (repl, filename, maxSize) -> fs.write fd, "#{code}\n" lastLine = code - repl.rli.on 'exit', -> fs.close fd + repl.on 'exit', -> fs.close fd # Add a command to show the history stack repl.commands[getCommandId(repl, 'history')] =