fix(server): release MatchResult back to pool after use

Add matcher.ReleaseMatchResult(result) in the base handler to prevent
sync.Pool object leak. Every Match() call acquires from pool but the
caller never returned objects, causing unbounded pool growth.
This commit is contained in:
xfy 2026-06-04 11:14:32 +08:00
parent 10f16bfda9
commit 2be6b67d0b

View File

@ -529,9 +529,10 @@ func (s *Server) startSingleMode() error {
result := locationEngine.Match(ctx.Path()) result := locationEngine.Match(ctx.Path())
if result != nil && result.Handler != nil { if result != nil && result.Handler != nil {
result.Handler(ctx) result.Handler(ctx)
matcher.ReleaseMatchResult(result)
return return
} }
// 无匹配,返回 404 matcher.ReleaseMatchResult(result)
ctx.SetStatusCode(404) ctx.SetStatusCode(404)
ctx.SetBodyString("Not Found") ctx.SetBodyString("Not Found")
} }