fix trap_listener crash when call `close`

This problem is occurring by variable scope.