Index: subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c =================================================================== --- subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c (revision 20409) +++ subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c (working copy) @@ -1569,19 +1569,24 @@ return err; } +static svn_error_t * +close_handler_pyio(void *baton) +{ + PyObject *py_io = baton; + Py_DECREF(py_io); + return SVN_NO_ERROR; +} + svn_stream_t * svn_swig_py_make_stream(PyObject *py_io, apr_pool_t *pool) { svn_stream_t *stream; - /* Borrow the caller's reference to py_io - this is safe only because the - * caller must have a reference in order to pass the object into the - * bindings, and we will be finished with the py_io object before we return - * to python. I.e. DO NOT STORE AWAY THE RESULTING svn_stream_t * for use - * over multiple calls into the bindings. */ + Py_INCREF(py_io); stream = svn_stream_create(py_io, pool); svn_stream_set_read(stream, read_handler_pyio); svn_stream_set_write(stream, write_handler_pyio); + svn_stream_set_close(stream, close_handler_pyio); return stream; }