Skip to content

Commit e71aed7

Browse files
resource/pack.go: Fix resource leaks in resource pack methods (#337)
1 parent c0fd04a commit e71aed7

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

minecraft/resource/pack.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ func createTempArchive(path string) (*os.File, error) {
297297
return nil, err
298298
}
299299
writer := zip.NewWriter(temp)
300+
defer writer.Close()
300301
if err := filepath.Walk(path, func(filePath string, info os.FileInfo, err error) error {
301302
if err != nil {
302303
return err
@@ -328,17 +329,16 @@ func createTempArchive(path string) (*os.File, error) {
328329
if err != nil {
329330
return fmt.Errorf("open resource pack file %v: %w", filePath, err)
330331
}
332+
defer file.Close()
331333
data, _ := io.ReadAll(file)
332334
// Write the original content into the 'zip file' so that we write compressed data to the file.
333335
if _, err := f.Write(data); err != nil {
334336
return fmt.Errorf("write file data to zip: %w", err)
335337
}
336-
_ = file.Close()
337338
return nil
338339
}); err != nil {
339340
return nil, fmt.Errorf("build zip archive: %w", err)
340341
}
341-
_ = writer.Close()
342342
return temp, nil
343343
}
344344

0 commit comments

Comments
 (0)