fix double-free/crash at session close