cmd: fix potential resource leaks

Signed-off-by: luchenhan <hanluchen@aliyun.com>
This commit is contained in:
luchenhan 2024-04-26 17:55:50 +08:00
parent ad4fb2c729
commit 4e14b1334a

View file

@ -182,12 +182,14 @@ func runCmd(ctx *cli.Context) error {
//Try reading from stdin
if hexcode, err = io.ReadAll(os.Stdin); err != nil {
fmt.Printf("Could not load code from stdin: %v\n", err)
triedb.Close()
os.Exit(1)
}
} else {
// Codefile with hex assembly
if hexcode, err = os.ReadFile(codeFileFlag); err != nil {
fmt.Printf("Could not load code from file: %v\n", err)
triedb.Close()
os.Exit(1)
}
}