From 517eacb4f9ca7276511841c63e2911d6ec94c22a Mon Sep 17 00:00:00 2001 From: ishanray Date: Wed, 30 Oct 2019 23:13:39 -0400 Subject: [PATCH 1/2] Update gin.go (#2110) --- gin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gin.go b/gin.go index 58631263..caf4cf2c 100644 --- a/gin.go +++ b/gin.go @@ -30,7 +30,7 @@ type HandlerFunc func(*Context) // HandlersChain defines a HandlerFunc array. type HandlersChain []HandlerFunc -// Last returns the last handler in the chain. ie. the last handler is the main own. +// Last returns the last handler in the chain. ie. the last handler is the main one. func (c HandlersChain) Last() HandlerFunc { if length := len(c); length > 0 { return c[length-1] From aabaccbba2b670e3625c9d9e89b4157a47f052b8 Mon Sep 17 00:00:00 2001 From: Shamus Taylor Date: Thu, 31 Oct 2019 09:52:02 -0500 Subject: [PATCH 2/2] Close files opened in static file handler (#2118) * Close files opened in static file handler * Do not use defer --- routergroup.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/routergroup.go b/routergroup.go index a1e6c928..2e7a5b90 100644 --- a/routergroup.go +++ b/routergroup.go @@ -193,13 +193,15 @@ func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileS file := c.Param("filepath") // Check if file exists and/or if we have permission to access it - if _, err := fs.Open(file); err != nil { + f, err := fs.Open(file) + if err != nil { c.Writer.WriteHeader(http.StatusNotFound) c.handlers = group.engine.noRoute // Reset index c.index = -1 return } + f.Close() fileServer.ServeHTTP(c.Writer, c.Request) }