justinas/nosurf — pull request #8 by dannyyoo (2014-07-07 17:22:18+00:00)
Title: Adds call to ctxClear to avoid memory leak.

The following test code shows that there's a memory leak across uses
of ServeHTTP.

----------------------------------------------------------------------
package main

import (
"github.com/justinas/nosurf"
"net/http"
"net/http/httptest"
)

func doNothing(w http.ResponseWriter, r *http.Request) {}

func dummyGet() *http.Request {
req, err := http.NewRequest("GET", "http://dum.my/", nil)
if err != nil {
panic(err)
}
return req
}

func main() {
h := nosurf.New(http.HandlerFunc(doNothing))
for {
recorder := httptest.NewRecorder()
h.ServeHTTP(recorder, dummyGet())
}
}
----------------------------------------------------------------------