Commits

Lenard Lindstrom  committed 82f658d

Another bug fix towards issue #175

This adds another missing `Py_DECREF()` for a returned PyNumber_Index object.
In chasing down the lockobj PyPixelArray struct field was removed, with
the `PixelArray` instance directly calling `PySurface_LockBy()` and
`PySurface_UnlockBy()`. The lifetime lock object was redundant and considered a
possible candidate for the leak. Also, the `PyObject_ClearWeakRefs()` call in
`_pxarray_dealloc()` was moved to the to of the slot function, as per the
[Python 3.3 weak reference support documentation](http://docs.python.org/3.3/extending/newtypes.html#weak-reference-support).

  • Participants
  • Parent commits 746036f

Comments (0)

Files changed (1)

File src/pixelarray.c

     PyObject *dict;        /* dict for subclassing */
     PyObject *weakrefs;    /* Weakrefs for subclassing */
     PyObject *surface;     /* Surface associated with the array */
-    PyObject *lock;        /* Lock object for the surface */
     Py_ssize_t shape[2];   /* (row,col) shape of array in pixels */
     Py_ssize_t strides[2]; /* (row,col) offsets in bytes */
     Uint8  *pixels;        /* Start of array data */
         self->parent = 0;
         self->surface = surface;
         Py_INCREF(surface);
-        self->lock = PySurface_LockLifetime(surface, (PyObject *)self);
-        if (!self->lock) {
+        if (!PySurface_LockBy(surface, (PyObject *)self)) {
             Py_DECREF(surface);
             Py_TYPE(self)->tp_free((PyObject *)self);
             return 0;
         surface = parent->surface;
         self->surface = surface;
         Py_INCREF(surface);
-        self->lock = parent->lock;
-        Py_INCREF(self->lock);
     }
     self->shape[0] = dim0;
     self->shape[1] = dim1;
 static void
 _pxarray_dealloc(PyPixelArray *self)
 {
+    if (self->weakrefs) {
+        PyObject_ClearWeakRefs((PyObject *)self);
+    }
     PyObject_GC_UnTrack(self);
-    if (self->weakrefs) {
-        PyObject_ClearWeakRefs ((PyObject *) self);
+    if (self->parent) {
+        Py_DECREF(self->parent);
     }
-    Py_XDECREF(self->lock);
-    Py_XDECREF(self->parent);
+    else {
+        PySurface_UnlockBy(self->surface, (PyObject *)self);
+    }
+    Py_DECREF(self->surface);
     Py_XDECREF(self->dict);
-    Py_DECREF(self->surface);
     Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
     if (self->dict) {
         Py_VISIT(self->dict);
     }
-    if (self->lock) {
-        Py_VISIT(self->lock);
-    }
     if (self->parent) {
         Py_VISIT((PyObject *)self->parent);
     }
         }
         /* A simple index. */
         i = PyNumber_AsSsize_t(val, PyExc_IndexError);
+        Py_DECREF(val);
 #else
         i = PyInt_Check(op) ? PyInt_AsLong (op) : PyLong_AsLong (op);
 #endif