CID-11036: Fix memory leak when we can't connect to a server

Annoyingly enough, I can't seem to be able to create a test case for it though