From 51079288923076d00a8b36ecec07980a158d742c Mon Sep 17 00:00:00 2001 From: zaddok Date: Fri, 9 Aug 2019 09:47:06 +1000 Subject: [PATCH] Fix potential memory leak Fix potential memory leak where zw is not Close() when an error occurs. --- file.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/file.go b/file.go index a9e7eecf..a4aa11d0 100644 --- a/file.go +++ b/file.go @@ -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 } }