Low: tools: be extra safe with freeing API connections when exiting
It shouldn't ever be needed, but just as a failsafe in case of bugs or
callbacks doing something unexpected, NULL the global API connection variables
before closing them (via a locally saved copy), so we can't possibly try to use
them after freeing them.