subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhuij...@apache.org
Subject svn commit: r1101835 - /subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
Date Wed, 11 May 2011 11:25:04 GMT
Author: rhuijben
Date: Wed May 11 11:25:04 2011
New Revision: 1101835

URL: http://svn.apache.org/viewvc?rev=1101835&view=rev
Log:
Avoid leaking file descriptors and object references in the python bindings,
by releasing the python object from the pool cleanup handler. Also call
the python close function when the stream is explicitly closed.

* subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
  (close_handler_pyio): Forward close to the python code, but don't decrement
    reference to python object yet.

  (svn_swig_py_stream_destroy): New function.
  (svn_swig_py_make_stream): Install svn_swig_py_stream_destroy as cleanup
    handler.

Patch by: Nick Piper <nick.piper{_AT_}logica.com>
          (tweaked by me)

Modified:
    subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c

Modified: subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c?rev=1101835&r1=1101834&r2=1101835&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c (original)
+++ subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c Wed May
11 11:25:04 2011
@@ -2108,10 +2108,27 @@ static svn_error_t *
 close_handler_pyio(void *baton)
 {
   PyObject *py_io = baton;
+  PyObject *result;
+  svn_error_t *err = NULL;
+
+  svn_swig_py_acquire_py_lock();
+  if ((result = PyObject_CallMethod(py_io, (char *)"close", NULL)) == NULL)
+    {
+      err = callback_exception_error();
+    }
+  Py_XDECREF(result);
+  svn_swig_py_release_py_lock();
+
+  return err;
+}
+
+static apr_status_t
+svn_swig_py_stream_destroy(void *py_io)
+{
   svn_swig_py_acquire_py_lock();
   Py_DECREF(py_io);
   svn_swig_py_release_py_lock();
-  return SVN_NO_ERROR;
+  return APR_SUCCESS;
 }
 
 svn_stream_t *
@@ -2123,6 +2140,8 @@ svn_swig_py_make_stream(PyObject *py_io,
   svn_stream_set_read(stream, read_handler_pyio);
   svn_stream_set_write(stream, write_handler_pyio);
   svn_stream_set_close(stream, close_handler_pyio);
+  apr_pool_cleanup_register(pool, py_io, svn_swig_py_stream_destroy,
+                            apr_pool_cleanup_null);
   Py_INCREF(py_io);
 
   return stream;



Mime
View raw message