From 4522708ddf66b4760dd21f22bd48eb0de867638f Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Sun, 24 Jan 2016 14:31:15 +0100 Subject: [PATCH] Updates #15 Prevent a potential file handle leak in sending update notifications via POST to mtwebmapper. --- cmd/mtredisalize/changetracker.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/mtredisalize/changetracker.go b/cmd/mtredisalize/changetracker.go index 87681c9..6819aee 100644 --- a/cmd/mtredisalize/changetracker.go +++ b/cmd/mtredisalize/changetracker.go @@ -64,8 +64,13 @@ func (ct *ChangeTracker) FlushChanges(url string) { log.Printf("WARN: encode changes to JSON failed: %s\n", err) return } - if _, err = http.Post( - url, "application/json", bytes.NewBuffer(buf.Bytes())); err != nil { + var resp *http.Response + resp, err = http.Post( + url, "application/json", bytes.NewBuffer(buf.Bytes())) + if resp != nil { + defer resp.Body.Close() + } + if err != nil { log.Printf("WARN: posting changes to %s failed: %s\n", url, err) } }()