From a0ee71234a3867fbbf9119f3ae57c16965280563 Mon Sep 17 00:00:00 2001 From: huangzw Date: Fri, 1 Mar 2024 18:42:50 +0800 Subject: [PATCH] Using temporary variables to save c.Keys and c.Params to prevent them from changing during the copying process. --- context.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/context.go b/context.go index 9a72bbc6..126d35db 100644 --- a/context.go +++ b/context.go @@ -115,17 +115,22 @@ func (c *Context) Copy() *Context { Request: c.Request, engine: c.engine, } + cp.writermem.ResponseWriter = nil cp.Writer = &cp.writermem cp.index = abortIndex cp.handlers = nil - cp.Keys = make(map[string]any, len(c.Keys)) - for k, v := range c.Keys { + + cKeys := c.Keys + cp.Keys = make(map[string]any, len(cKeys)) + for k, v := range cKeys { cp.Keys[k] = v } - paramsCopy := make([]Param, len(c.Params)) - copy(paramsCopy, c.Params) - cp.Params = paramsCopy + + cParams := c.Params + cp.Params = make([]Param, len(cParams)) + copy(cp.Params, cParams) + return &cp }