From dd0547fb2d87302006377d7608b1e4ba3b45caa5 Mon Sep 17 00:00:00 2001 From: "fj.jin" Date: Tue, 17 Nov 2020 00:19:04 +0800 Subject: [PATCH] make it clear that the context will be reset after the request ends, otherwise, the timing of the pointer context reset is uncontrollable without constraints --- gin.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gin.go b/gin.go index 1e126179..8aeb425b 100644 --- a/gin.go +++ b/gin.go @@ -165,7 +165,10 @@ func Default() *Engine { func (engine *Engine) allocateContext() *Context { v := make(Params, 0, engine.maxParams) - return &Context{engine: engine, params: &v} + c := &Context{engine: engine, params: &v} + // init ctx struct + c.reset() + return c } // Delims sets template left and right delims and returns a Engine instance. @@ -371,10 +374,11 @@ func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request) { c := engine.pool.Get().(*Context) c.writermem.reset(w) c.Request = req - c.reset() engine.handleHTTPRequest(c) + // clear request data + c.reset() engine.pool.Put(c) }