move middle_t::cleanup code into destructor

Fixes a whole bunch of leaking postgres connections. cleanup() wasn't called anywhere anymore.