Explorar o código

Fix potential memory leak

Fix potential memory leak where zw is not Close() when an error occurs.
zaddok %!s(int64=6) %!d(string=hai) anos
pai
achega
5107928892
Modificáronse 1 ficheiros con 2 adicións e 0 borrados
  1. 2 0
      file.go

+ 2 - 0
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
 		}
 	}