diff --git a/chain/vectors/vectors_test.go b/chain/vectors/vectors_test.go index c9ebc98fa..587ea22d1 100644 --- a/chain/vectors/vectors_test.go +++ b/chain/vectors/vectors_test.go @@ -18,6 +18,7 @@ func LoadVector(t *testing.T, f string, out interface{}) { if err != nil { t.Fatal(err) } + defer fi.Close() if err := json.NewDecoder(fi).Decode(out); err != nil { t.Fatal(err) diff --git a/cmd/lotus-bench/import.go b/cmd/lotus-bench/import.go index 3c56a5707..9ea3e8d0f 100644 --- a/cmd/lotus-bench/import.go +++ b/cmd/lotus-bench/import.go @@ -466,6 +466,7 @@ var importAnalyzeCmd = &cli.Command{ if err != nil { return err } + defer fi.Close() //nolint:errcheck const nWorkers = 16 jsonIn := make(chan []byte, 2*nWorkers) diff --git a/cmd/lotus-seed/genesis.go b/cmd/lotus-seed/genesis.go index 45397af35..99a56af57 100644 --- a/cmd/lotus-seed/genesis.go +++ b/cmd/lotus-seed/genesis.go @@ -240,6 +240,7 @@ func parseMultisigCsv(csvf string) ([]GenAccountEntry, error) { if err != nil { return nil, xerrors.Errorf("read multisig csv: %w", err) } + defer fileReader.Close() //nolint:errcheck r := csv.NewReader(fileReader) records, err := r.ReadAll() if err != nil { diff --git a/cmd/lotus-seed/main.go b/cmd/lotus-seed/main.go index cf0f166d9..67762e4dd 100644 --- a/cmd/lotus-seed/main.go +++ b/cmd/lotus-seed/main.go @@ -155,6 +155,9 @@ var aggregateManifestsCmd = &cli.Command{ } inputs = append(inputs, val) + if err := fi.Close(); err != nil { + return err + } } output := make(map[string]genesis.Miner) diff --git a/cmd/lotus-shed/import-car.go b/cmd/lotus-shed/import-car.go index e54089df0..3347f9825 100644 --- a/cmd/lotus-shed/import-car.go +++ b/cmd/lotus-shed/import-car.go @@ -65,11 +65,17 @@ var importCarCmd = &cli.Command{ fmt.Println() return ds.Close() default: + if err := f.Close(); err != nil { + return err + } fmt.Println() return err case nil: fmt.Printf("\r%s", blk.Cid()) if err := bs.Put(blk); err != nil { + if err := f.Close(); err != nil { + return err + } return xerrors.Errorf("put %s: %w", blk.Cid(), err) } } diff --git a/cmd/lotus-shed/keyinfo.go b/cmd/lotus-shed/keyinfo.go index 028ead413..d4272e5bc 100644 --- a/cmd/lotus-shed/keyinfo.go +++ b/cmd/lotus-shed/keyinfo.go @@ -1,6 +1,7 @@ package main import ( + "bufio" "encoding/base64" "encoding/hex" "encoding/json" @@ -64,10 +65,12 @@ var keyinfoImportCmd = &cli.Command{ input = os.Stdin } else { var err error - input, err = os.Open(cctx.Args().First()) + inputFile, err := os.Open(cctx.Args().First()) if err != nil { return err } + defer inputFile.Close() + input = bufio.NewReader(inputFile) } encoded, err := ioutil.ReadAll(input) @@ -174,10 +177,12 @@ var keyinfoInfoCmd = &cli.Command{ input = os.Stdin } else { var err error - input, err = os.Open(cctx.Args().First()) + inputFile, err := os.Open(cctx.Args().First()) if err != nil { return err } + defer inputFile.Close() + input = bufio.NewReader(inputFile) } encoded, err := ioutil.ReadAll(input) diff --git a/cmd/lotus/daemon.go b/cmd/lotus/daemon.go index bb17c0d87..45a12fe98 100644 --- a/cmd/lotus/daemon.go +++ b/cmd/lotus/daemon.go @@ -317,6 +317,7 @@ func ImportChain(r repo.Repo, fname string) error { if err != nil { return err } + defer fi.Close() //nolint:errcheck lr, err := r.Lock(repo.FullNode) if err != nil { diff --git a/node/impl/client/client.go b/node/impl/client/client.go index e3eefd3f9..048d0cf93 100644 --- a/node/impl/client/client.go +++ b/node/impl/client/client.go @@ -494,6 +494,7 @@ func (a *API) ClientCalcCommP(ctx context.Context, inpath string, miner address. if err != nil { return nil, err } + defer rdr.Close() stat, err := rdr.Stat() if err != nil { @@ -554,6 +555,7 @@ func (a *API) clientImport(ctx context.Context, ref api.FileRef, store *importmg if err != nil { return cid.Undef, err } + defer f.Close() stat, err := f.Stat() if err != nil { diff --git a/node/repo/fsrepo.go b/node/repo/fsrepo.go index 11d1cb5e7..470d016cd 100644 --- a/node/repo/fsrepo.go +++ b/node/repo/fsrepo.go @@ -390,6 +390,7 @@ func (fsr *fsLockedRepo) List() ([]string, error) { if err != nil { return nil, xerrors.Errorf("opening dir to list keystore: %w", err) } + defer dir.Close() //nolint:errcheck files, err := dir.Readdir(-1) if err != nil { return nil, xerrors.Errorf("reading keystore dir: %w", err)