Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Each request must be cleared otherwise memory leaks #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ func Sessions(name string, store Store) negroni.HandlerFunc {
// Use before hook to save out the session
rw := res.(negroni.ResponseWriter)
rw.Before(func(negroni.ResponseWriter) {
if s.Written() {
check(s.Session().Save(r, res))
if s.session != nil && s.Written() {
check(s.session.Save(r, res))
}
gContext.Clear(s.request)
})

// Wrap our request with the new context
Expand Down Expand Up @@ -154,9 +155,8 @@ func (s *session) Clear() {
if sess == nil {
return
}
sess.Values = nil
sess.Values = map[interface{}]interface{}{}
s.written = true
gContext.Clear(s.request)
}

func (s *session) AddFlash(value interface{}, vars ...string) {
Expand Down Expand Up @@ -194,7 +194,7 @@ func (s *session) Options(options Options) {
func (s *session) Session() *sessions.Session {
if s.session == nil {
var err error
s.session, err = s.store.Get(s.request, s.name)
s.session, err = sessions.GetRegistry(s.request).Get(s.store, s.name)
check(err)
}

Expand Down