defer in loop may cause resource leak

defer statement executes only when function return, and the resource still be hold during loop. Release the resource manually when not needed.
pull/3465/head
oilbeater 7 years ago
parent 2a9a9f1851
commit 0764d95a03

@ -193,10 +193,11 @@ func (g *TarGzExtractor) Extract(buffer *bytes.Buffer, targetDir string) error {
if err != nil {
return err
}
defer outFile.Close()
if _, err := io.Copy(outFile, tarReader); err != nil {
outFile.Close()
return err
}
outFile.Close()
default:
return fmt.Errorf("unknown type: %b in %s", header.Typeflag, header.Name)
}

Loading…
Cancel
Save