Author: Matti Picus <[email protected]>
Branch: issue2444
Changeset: r89175:041bc115e0bd
Date: 2016-12-19 06:20 +0200
http://bitbucket.org/pypy/pypy/changeset/041bc115e0bd/

Log:    failing test for leak in PyMemoryView_GET_BUFFER

diff --git a/pypy/module/cpyext/memoryobject.py 
b/pypy/module/cpyext/memoryobject.py
--- a/pypy/module/cpyext/memoryobject.py
+++ b/pypy/module/cpyext/memoryobject.py
@@ -173,5 +173,8 @@
         view.c_buf = rffi.cast(rffi.VOIDP, rffi.str2charp(space.str_w(w_s), 
track_allocation=False))
         rffi.setintfield(view, 'c_readonly', 1)
         isstr = True
+    # XXX leaks the view object and never decrefs the view.c_obj
+    #     In cpython the view is a field of the PyMemoryViewObject
+    #     and view.obj is decrefed in memory_dealloc
     return view
 
diff --git a/pypy/module/cpyext/test/buffer_test.c 
b/pypy/module/cpyext/test/buffer_test.c
--- a/pypy/module/cpyext/test/buffer_test.c
+++ b/pypy/module/cpyext/test/buffer_test.c
@@ -190,11 +190,18 @@
 {
     Py_buffer* view = NULL;
     PyObject* obj = PyTuple_GetItem(args, 0);
+    int before_cnt = obj->ob_refcnt;
     PyObject* memoryview = PyMemoryView_FromObject(obj);
     if (memoryview == NULL)
         return PyInt_FromLong(-1);
     view = PyMemoryView_GET_BUFFER(memoryview);
     Py_DECREF(memoryview);
+    if (obj->ob_refcnt != before_cnt)
+    {
+        PyErr_SetString(PyExc_RuntimeError,
+            "leaking view->obj from PyMemoryView_GET_BUFFER");
+        return NULL;
+    }
     return PyInt_FromLong(view->len);
 }
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to