Try to fix the rare segfault associated with console switch.

This only happens every couple weeks, and hard to reproduce,
so not sure this is the fix, hope it is.