Fixes #374. Fix for memory leak in session handler