Skip to content

Commit

Permalink
Fix image file cleanup (#119)
Browse files Browse the repository at this point in the history
fix(writer/standard): closed open file descriptor in in writer option and test cases
* Option: close image files after use
* TestCases: close open files from tests
  • Loading branch information
epelc authored Dec 5, 2024
1 parent e166367 commit 4bcbcb5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions writer/standard/image_option_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func WithLogoImageFileJPEG(f string) ImageOption {
fmt.Printf("could not open file(%s), error=%v\n", f, err)
return
}
defer fd.Close()

img, err := jpeg.Decode(fd)
if err != nil {
Expand All @@ -114,6 +115,7 @@ func WithLogoImageFilePNG(f string) ImageOption {
fmt.Printf("Open file(%s) failed: %v\n", f, err)
return
}
defer fd.Close()

img, err := png.Decode(fd)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions writer/standard/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ func hashFile(filename string) (string, error) {
if err != nil {
return "", err
}
defer fd1.Close()

bytes, err := io.ReadAll(fd1)
if err != nil {
return "", err
Expand All @@ -140,6 +142,7 @@ func statImage(filename string) (w, h int, err error) {
if err != nil {
return 0, 0, err
}
defer fd.Close()

img, err := png.Decode(fd)
if err != nil {
Expand Down

0 comments on commit 4bcbcb5

Please sign in to comment.