Fix potential memory leak

Fix potential memory leak where zw is not Close() when an error occurs.
formula
zaddok 6 years ago committed by GitHub
parent 448f5524a8
commit 5107928892
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -109,10 +109,12 @@ func (f *File) WriteToBuffer() (*bytes.Buffer, error) {
for path, content := range f.XLSX { for path, content := range f.XLSX {
fi, err := zw.Create(path) fi, err := zw.Create(path)
if err != nil { if err != nil {
zw.Close()
return buf, err return buf, err
} }
_, err = fi.Write(content) _, err = fi.Write(content)
if err != nil { if err != nil {
zw.Close()
return buf, err return buf, err
} }
} }

Loading…
Cancel
Save