tstest/integration: stop leaking zstd.Decoders

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
Josh Bleecher Snyder 2021-11-30 13:44:50 -08:00 committed by Josh Bleecher Snyder
parent 124363e0ca
commit b800663779
1 changed files with 5 additions and 1 deletions

View File

@ -29,6 +29,7 @@ import (
"testing"
"time"
"github.com/klauspost/compress/zstd"
"go4.org/mem"
"tailscale.com/derp"
"tailscale.com/derp/derphttp"
@ -239,12 +240,15 @@ func (lc *LogCatcher) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var body io.Reader = r.Body
if r.Header.Get("Content-Encoding") == "zstd" {
var err error
body, err = smallzstd.NewDecoder(body)
var dec *zstd.Decoder
dec, err = smallzstd.NewDecoder(body)
if err != nil {
log.Printf("bad caught zstd: %v", err)
http.Error(w, err.Error(), 400)
return
}
defer dec.Close()
body = dec
}
bodyBytes, _ := ioutil.ReadAll(body)