ssh->mainchan can be NULL; try not to segfault in that situation.