So this was the actual bug?
2760 /* Ask holding process to free window and switch to console window */
Also, if you're going to do this, could you please remove this conditional?
2777 /* Switch back to saved window */
2778 if (vd->vd_savedwindow != NULL)
Is there a better debug message that can be provided for this and the item below, e.g. "Cannot switch vw (is NULL)", etc (otherwise I can't distinguish this error from the other, can I)?.
Is there a reason why this is returning 0 and the previous error condition is returning EINVAL?
I think it would be a very rare problem in practice, but should be considered. Would if (vw == curvw || vw == curvw->vw_switch_to == vw) be an appropriate test? Or maybe two separate tests so different diagnostics can be used in each.