1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

fix history file descriptor leak

This commit is contained in:
Sangmin Yoon 2015-04-22 15:26:44 +09:00
parent 140a73dca7
commit 8b463cd3ad
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')] =