Leonardo USB won't stay connected

Okay, with a bit of luck and good timing, I managed to get blink to compile & upload before it disconnects and the problem has gone away!

Clearly my code did mess up the USB connection in someway...