Skip to content

Commit

Permalink
defer in loop may cause resource leak
Browse files Browse the repository at this point in the history
defer statement executes only when function return, and the resource still be hold during loop. Release the resource manually when not needed.
  • Loading branch information
oilbeater committed Feb 9, 2018
1 parent 2a9a9f1 commit 0764d95
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/plugin/installer/http_installer.go
Expand Up @@ -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)
}
Expand Down

0 comments on commit 0764d95

Please sign in to comment.