Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

History file handle leak #113

Open
crweatherly opened this issue Mar 28, 2019 · 0 comments
Open

History file handle leak #113

crweatherly opened this issue Mar 28, 2019 · 0 comments
Labels

Comments

@crweatherly
Copy link

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)
 }
@abiosoft abiosoft added the bug label Mar 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants