Fix resource leaks on exception paths

Make it clear that the server socket isn't a leaked resource
Fix resource leak CID-1116654
Fix CID-1116645
Merge branch 'bugfix/CID-116538'