Skip to content

Commit 0552008

Browse files
committed
Deferred defer
Signed-off-by: Vishal Rana <vr@labstack.com>
1 parent 2342df3 commit 0552008

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

echo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ func (e *Echo) Index(file string) {
198198

199199
func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
200200
h, c, echo := e.Router.Find(r.Method, r.URL.Path)
201-
defer e.pool.Put(c)
202201
if echo != nil {
203202
e = echo
204203
}
@@ -212,6 +211,7 @@ func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
212211
}
213212
// Handler
214213
h(c)
214+
e.pool.Put(c)
215215
}
216216

217217
// Run a server

router.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ func (r *router) Find(method, path string) (h HandlerFunc, c *Context, echo *Ech
216216

217217
func (r *router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
218218
h, c, _ := r.Find(req.Method, req.URL.Path)
219-
defer r.echo.pool.Put(c)
220219
c.Response.ResponseWriter = w
221220
if h != nil {
222221
h(c)
223222
} else {
224223
r.echo.notFoundHandler(c)
225224
}
225+
r.echo.pool.Put(c)
226226
}

0 commit comments

Comments
 (0)