fixing up leaks and correcting connection release code to also invalidate