Skip to content

Commit

Permalink
fix: cosmovisor: fix (*Config.SetCurrentUpgrade file leak on failed J…
Browse files Browse the repository at this point in the history
…SON marshal+write (#12750)
  • Loading branch information
odeke-em authored Jul 27, 2022
1 parent a8a52d0 commit 37e765d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions cosmovisor/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func (cfg *Config) validate() []error {
}

// SetCurrentUpgrade sets the named upgrade to be the current link, returns error if this binary doesn't exist
func (cfg *Config) SetCurrentUpgrade(u upgradetypes.Plan) error {
func (cfg *Config) SetCurrentUpgrade(u upgradetypes.Plan) (rerr error) {
// ensure named upgrade exists
bin := cfg.UpgradeBin(u.Name)

Expand Down Expand Up @@ -299,14 +299,19 @@ func (cfg *Config) SetCurrentUpgrade(u upgradetypes.Plan) error {
if err != nil {
return err
}
defer func() {
cerr := f.Close()
if rerr == nil {
rerr = cerr
}
}()

bz, err := json.Marshal(u)
if err != nil {
return err
}
if _, err := f.Write(bz); err != nil {
return err
}
return f.Close()
_, err = f.Write(bz)
return err
}

func (cfg *Config) UpgradeInfo() (upgradetypes.Plan, error) {
Expand Down

0 comments on commit 37e765d

Please sign in to comment.