From beb6a843c6f970dea50e2c30833b74c798ee7848 Mon Sep 17 00:00:00 2001 From: Jamie Sinn Date: Wed, 4 Sep 2024 16:29:04 -0400 Subject: [PATCH] Add defer cleanup to body reads (#25) --- http_endpoints.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/http_endpoints.go b/http_endpoints.go index b556302..ff41508 100644 --- a/http_endpoints.go +++ b/http_endpoints.go @@ -97,6 +97,7 @@ func BatchEvents() gin.HandlerFunc { c.JSON(http.StatusInternalServerError, gin.H{"message": "Error reading request body: " + err.Error()}) return } + defer c.Request.Body.Close() var batchEvents map[string]interface{} err = json.Unmarshal(body, &batchEvents) @@ -204,7 +205,6 @@ func GetConfig(client *devcycle.Client, version ...string) gin.HandlerFunc { if c.Request.RemoteAddr == "" { hostname = fmt.Sprintf("unix:%s", instance.UnixSocketPath) } - fmt.Println(c.Request) if val, ok := config["sse"]; ok { path := val.(map[string]interface{})["path"].(string) @@ -256,7 +256,7 @@ func getUserFromBody(c *gin.Context) *devcycle.User { }) return nil } - + defer c.Request.Body.Close() err = json.Unmarshal(jsonBody, &user) if err != nil { c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{ @@ -280,6 +280,8 @@ func getEventFromBody(c *gin.Context) *devcycle.UserDataAndEventsBody { }) return nil } + defer c.Request.Body.Close() + err = json.Unmarshal(jsonBody, &event) if err != nil { c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{