From a2fcdeb1ef3dd8da8a596f81b160d32110f72f24 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Thu, 16 Apr 2020 20:16:16 +0200 Subject: [PATCH] Defer finalizer (#7129) Signed-off-by: Julien Pivotto --- web/api/v1/api.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/api/v1/api.go b/web/api/v1/api.go index 204b2ff38..d9f3ea237 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -249,6 +249,9 @@ func (api *API) Register(r *route.Router) { hf := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { httputil.SetCORS(w, api.CORSOrigin, r) result := f(r) + if result.finalizer != nil { + defer result.finalizer() + } if result.err != nil { api.respondError(w, result.err, result.data) } else if result.data != nil { @@ -256,9 +259,6 @@ func (api *API) Register(r *route.Router) { } else { w.WriteHeader(http.StatusNoContent) } - if result.finalizer != nil { - result.finalizer() - } }) return api.ready(httputil.CompressionHandler{ Handler: hf,