Richard Clark points out a missing check for ssh->mainchan being NULL.