Fix memory leak with gen.engine, RequestHandler.flush, and closed connections.

This was unfortunately difficult to reproduce in a unit test, even though
the test program attached to bug 660 easily reproduces it.

Closes #660.