Skip to content

Commit

Permalink
handlers/objects: Drop redundant nil check from UploadContainerObject
Browse files Browse the repository at this point in the history
According to the code, operand cannot be nil. Otherwise, the
unconditional `io.CopyBuffer` call within the same method would be
unsafe and removed if-condition only raised suspicions of potential
panic.

Deferred action is also moved "closer" to the file init.

Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
  • Loading branch information
cthulhu-rider committed Jun 25, 2024
1 parent 327445c commit eece01f
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions handlers/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,15 @@ func (a *RestAPI) UploadContainerObject(ctx echo.Context, containerID apiserver.
resp := a.logAndGetErrorResponse(fmt.Sprintf("get file %q from HTTP request", fileKey), err)
return ctx.JSON(http.StatusBadRequest, resp)
}
defer func() {
err := file.Close()
a.log.Debug(
"close temporary multipart/form file",
zap.Stringer("address", addr),
zap.String("filename", header.Filename),
zap.Error(err),
)
}()

break
}
Expand All @@ -963,19 +972,6 @@ func (a *RestAPI) UploadContainerObject(ctx echo.Context, containerID apiserver.
return ctx.JSON(http.StatusBadRequest, resp)
}

defer func() {
if file == nil {
return
}
err := file.Close()
a.log.Debug(
"close temporary multipart/form file",
zap.Stringer("address", addr),
zap.String("filename", header.Filename),
zap.Error(err),
)
}()

filtered, err := filterHeaders(a.log, ctx.Request().Header)
if err != nil {
resp := a.logAndGetErrorResponse("could not process headers", err)
Expand Down

0 comments on commit eece01f

Please sign in to comment.