bradleyfalzon / closecheck

Check for missing close method calls on objects that may require them - SEE EPILOGUE
Apache License 2.0
1 stars 0 forks source link

Libraries providing Constructor and Close method #3

Closed bradleyfalzon closed 8 years ago

bradleyfalzon commented 8 years ago

Library authors that have a constructor, such as func New() *T which also has a func (*T) Close() error will have an error reported in the constructor.

This maybe fixed with some special case handling by checking if the type has a locally defined Close() method (somehow).

bradleyfalzon commented 8 years ago

Also, go-logging/syslog.go provide a New-style constructor, and exposes a syslog.Writer to a client library. This would be fine if the authors have left it up to the consumers to close the writer.

Perhaps when an object is returned in a non-main package, it can't reliably be checked.

bradleyfalzon commented 8 years ago

There are some cases where a variant of this behaviour is correct, in bayesian/bayesian.go the file at 415 is never closed.

413 // Serialize this classifier to a file.
414 func (c *Classifier) WriteToFile(name string) (err error) {
415     file, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE, 0644)
416     if err != nil {
417         return err
418     }
419     return c.WriteTo(file)
420 }
...
442 // Serialize this classifier to GOB and write to Writer.
443 func (c *Classifier) WriteTo(w io.Writer) (err error) {
444     enc := gob.NewEncoder(w)
445     err = enc.Encode(&serializableClassifier{c.Classes, c.learned, c.seen, c.datas})
446     return
447 }