From 27f76afb288b7c24f5ce1d0274ed3ae73c77e076 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Tue, 24 Jan 2017 20:02:41 -0500 Subject: Closing response body when fetching link previews (#5181) --- api/api.go | 8 ++++++++ api/post.go | 1 + api/webrtc.go | 8 -------- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/api/api.go b/api/api.go index 59c547b8c..3d2217ef5 100644 --- a/api/api.go +++ b/api/api.go @@ -4,6 +4,7 @@ package api import ( + "io/ioutil" "net/http" "github.com/gorilla/mux" @@ -143,3 +144,10 @@ func ReturnStatusOK(w http.ResponseWriter) { m[model.STATUS] = model.STATUS_OK w.Write([]byte(model.MapToJson(m))) } + +func closeBody(r *http.Response) { + if r.Body != nil { + ioutil.ReadAll(r.Body) + r.Body.Close() + } +} diff --git a/api/post.go b/api/post.go index 9121adb92..13cfecfdf 100644 --- a/api/post.go +++ b/api/post.go @@ -668,6 +668,7 @@ func getOpenGraphMetadata(c *Context, w http.ResponseWriter, r *http.Request) { og := opengraph.NewOpenGraph() res, err := http.Get(props["url"].(string)) + defer closeBody(res) if err != nil { writeOpenGraphToResponse(w, og) return diff --git a/api/webrtc.go b/api/webrtc.go index 15b7cfa4f..7ea6b2e42 100644 --- a/api/webrtc.go +++ b/api/webrtc.go @@ -8,7 +8,6 @@ import ( "crypto/sha1" "crypto/tls" "encoding/base64" - "io/ioutil" "net/http" "strconv" "strings" @@ -108,10 +107,3 @@ func generateTurnPassword(username string, secret string) string { h.Write([]byte(username)) return base64.StdEncoding.EncodeToString(h.Sum(nil)) } - -func closeBody(r *http.Response) { - if r.Body != nil { - ioutil.ReadAll(r.Body) - r.Body.Close() - } -} -- cgit v1.2.3-1-g7c22