Merge pull request #3953 from sixmen/fix_repl_fd_leak

fix history file descriptor leak
This commit is contained in:
Michael Ficarra 2015-04-23 06:46:50 -07:00
commit 1e62781759
2 changed files with 4 additions and 2 deletions

View File

@ -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')] = {

View File

@ -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')] =