Fix potential memory leak

Fix potential memory leak where zw is not Close() when an error occurs.
This commit is contained in:
zaddok 2019-08-09 09:47:06 +10:00 committed by GitHub
parent 448f5524a8
commit 5107928892
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

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