FIX: memory leak when an error happens in the connection