From 70256d1a0076c956a8b882ae002639a7fdef129c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 3 Sep 2014 19:06:34 +0200 Subject: [PATCH] remote: clear self handle only on error When setting the callbacks fails, we want to clear self._self_handle so we don't leak a pointer to ourselves. The current code used a 'finally' clause which clears it unconditionally, which means that by the time the fetch starts, we have no guarantee that the handle will be valid. Replace that with an except and re-raise to make sure we only clear it here if there was an error. --- pygit2/remote.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pygit2/remote.py b/pygit2/remote.py index bda0761..3e08d3a 100644 --- a/pygit2/remote.py +++ b/pygit2/remote.py @@ -210,8 +210,9 @@ class Remote(object): err = C.git_remote_set_callbacks(self._remote, callbacks) try: check_error(err) - finally: + except: self._self_handle = None + raise if signature: ptr = signature._pointer[:]