subvertpy-users team mailing list archive
-
subvertpy-users team
-
Mailing list archive
-
Message #00020
Re: [PATCH 3 of 3] Fix a memory leak
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.
Cheers,
Jelmer
Attachment:
signature.asc
Description: This is a digitally signed message part
Follow ups
References