Fix memory leak when no connection