Skip to content

Commit e34004c

Browse files
committed
fix: close image file handle
1 parent 592dc45 commit e34004c

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎api/application.go‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package api
33
import (
44
"errors"
55
"fmt"
6+
"io"
67
"net/http"
78
"os"
89
"path/filepath"
@@ -421,8 +422,16 @@ func (a *ApplicationAPI) UploadApplicationImage(ctx *gin.Context) {
421422
return
422423
}
423424
head := make([]byte, 261)
424-
open, _ := file.Open()
425-
open.Read(head)
425+
open, err := file.Open()
426+
if err != nil {
427+
ctx.AbortWithError(500, err)
428+
return
429+
}
430+
defer open.Close()
431+
if _, err := open.Read(head); err != nil && err != io.EOF {
432+
ctx.AbortWithError(500, err)
433+
return
434+
}
426435
if !filetype.IsImage(head) {
427436
ctx.AbortWithError(400, errors.New("file must be an image"))
428437
return

0 commit comments

Comments
 (0)