Browse Source

Add a bunch of missed defer f.Close() -- none of which I believe could lea file descriptors though from open files (#531)

Maybe we have a socket leak and/or some goroutine leaks?

Co-authored-by: James Mills <prologic@shortcircuit.net.au>
Reviewed-on: #531
Reviewed-by: xuu <xuu@noreply@mills.io>
Co-authored-by: James Mills <james@mills.io>
Co-committed-by: James Mills <james@mills.io>
pull/532/head
James Mills 3 weeks ago
parent
commit
799e4564e9
  1. 1
      client/config.go
  2. 1
      internal/cache.go
  3. 1
      internal/config.go
  4. 1
      internal/twt.go
  5. 3
      types/twt_test.go

1
client/config.go

@ -35,6 +35,7 @@ func (c *Config) Save(path string) error {
if err != nil {
return err
}
defer f.Close()
data, err := yaml.Marshal(c)
if err != nil {

1
internal/cache.go

@ -184,7 +184,6 @@ func (cache *Cache) Store(conf *Config) error {
log.WithError(err).Error("error opening cache file for writing")
return err
}
defer f.Close()
if _, err = f.Write(b.Bytes()); err != nil {

1
internal/config.go

@ -298,6 +298,7 @@ func (s *Settings) Save(path string) error {
if err != nil {
return err
}
defer f.Close()
data, err := yaml.MarshalWithOptions(s, yaml.Indent(4))
if err != nil {

1
internal/twt.go

@ -187,6 +187,7 @@ func GetAllTwts(conf *Config, name string) (types.Twts, error) {
log.WithError(err).Warnf("error opening feed: %s", fn)
return nil, err
}
defer f.Close()
t, err := types.ParseFile(f, twter)
if err != nil {
log.WithError(err).Errorf("error processing feed %s", fn)

3
types/twt_test.go

@ -21,6 +21,7 @@ func BenchmarkAll(b *testing.B) {
fmt.Println(err)
b.FailNow()
}
defer f.Close()
wr := nilWriter{}
twter := types.Twter{Nick: "prologic", URL: "https://twtxt.net/user/prologic/twtxt.txt"}
@ -58,6 +59,7 @@ func BenchmarkParse(b *testing.B) {
fmt.Println(err)
b.FailNow()
}
defer f.Close()
twter := types.Twter{Nick: "prologic", URL: "https://twtxt.net/user/prologic/twtxt.txt"}
@ -88,6 +90,7 @@ func BenchmarkOutput(b *testing.B) {
fmt.Println(err)
b.FailNow()
}
defer f.Close()
wr := nilWriter{}
twter := types.Twter{Nick: "prologic", URL: "https://twtxt.net/user/prologic/twtxt.txt"}

Loading…
Cancel
Save