Skip to content

media upload cleanup bug #1423

@gabriel-vasile

Description

@gabriel-vasile

listmonk/cmd/media.go

Lines 62 to 85 in a440b79

fName, err = app.media.Put(fName, contentType, src)
if err != nil {
app.log.Printf("error uploading file: %v", err)
cleanUp = true
return echo.NewHTTPError(http.StatusInternalServerError,
app.i18n.Ts("media.errorUploading", "error", err.Error()))
}
var (
thumbfName = ""
width = 0
height = 0
)
defer func() {
// If any of the subroutines in this function fail,
// the uploaded image should be removed.
if cleanUp {
app.media.Delete(fName)
if thumbfName != "" {
app.media.Delete(thumbfName)
}
}
}()

when err != nil in this code there should be cleanup done, but the cleanup function has not been yet deferred.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingrefactorCode refactor or cleanup with no functional changes

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions