abiosoft / abiosoft/ishell

History file handle leak

オープン
#113 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug
主要言語
Go
スター
1.8k
フォーク
213
PR マージ指標
30日以内にマージされた PR はありません

説明

The history file is not closed when it is reset, resulting in leaked file handles.

Here's a program that demonstrates the bug:
```
package main

import "gopkg.in/abiosoft/ishell.v2"

func main() {
shell := ishell.New()

shell.AddCmd(&ishell.Cmd{
Name: "on",
Func: func(ctx *ishell.Context) {
shell.SetHistoryPath("test-history")
},
})
shell.AddCmd(&ishell.Cmd{
Name: "off",
Func: func(ctx *ishell.Context) {
shell.SetHistoryPath("")
},
})

shell.Run()
}
```

By watching the output of `lsof -c main` on *nix can see that every call to `on` leaves the previous history file handle open. `off` does not close the existing file handle either.

It seems you need something like:
```
diff --git a/ishell.go b/ishell.go
index 098af06..c0545c1 100644
--- a/ishell.go
+++ b/ishell.go
@@ -393,6 +393,7 @@ func (s *Shell) SetHistoryPath(path string) {
// Instance.
config := s.reader.scanner.Config.Clone()
config.HistoryFile = path
+ s.reader.scanner.Close()
s.reader.scanner, _ = readline.NewEx(config)
}
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。