← Back to team overview

subvertpy-users team mailing list archive

Re: [PATCH 3 of 3] Fix a memory leak

 

On 14 Sep 2010, at 19:58, Jelmer Vernooij wrote:

Hi Dan,

On Tue, 2010-09-14 at 19:15 +0200, Dan Villiom Podlaski Christiansen
wrote:
# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr@xxxxxxxxx>
# Date 1284483800 -7200
# Node ID 63f87ad6cb314faddf37ebf3e1fce4840ee0fa94
# Parent  f11c9e3595a00e2e32bc713cd92f46275b1fe6f9
Fix a memory leak.

diff --git a/subvertpy/util.c b/subvertpy/util.c
--- a/subvertpy/util.c
+++ b/subvertpy/util.c
@@ -517,7 +517,6 @@ svn_stream_t *new_py_stream(apr_pool_t *
						"Unable to create a Subversion stream");
		return NULL;
	}
-	Py_INCREF(py);
	svn_stream_set_read(stream, py_stream_read);
	svn_stream_set_write(stream, py_stream_write);
	svn_stream_set_close(stream, py_stream_close);
We need the INCREF here, because if our Python caller drops their
reference to py after this function has been called there may still be
something else that's using the Subversion stream object and we thus
need to make sure that the python object stays around until the svn
stream is closed. If we don't do this then calls to
svn_stream_read/svn_stream_write may end up accessing a python object
that has already been freed.

Note that the py_stream_close callback decreases the reference counter
so there should be no leaking here at the moment.

I just did a bit of testing, and it seems you're right that this isn't the leak I was looking for. Sorry 'bout the disturbance! (And the long reply time too.)

--

Dan Villiom Podlaski Christiansen
danchr@xxxxxxxxx

Attachment: smime.p7s
Description: S/MIME cryptographic signature


References