[Numpy-svn] r3475 - trunk/numpy/core/src

numpy-svn at scipy.org numpy-svn at scipy.org
Mon Dec 4 14:32:42 CST 2006


Author: oliphant
Date: 2006-12-04 14:32:39 -0600 (Mon, 04 Dec 2006)
New Revision: 3475

Modified:
   trunk/numpy/core/src/multiarraymodule.c
Log:
Fix reference counting with PyArray_ArgSort

Modified: trunk/numpy/core/src/multiarraymodule.c
===================================================================
--- trunk/numpy/core/src/multiarraymodule.c	2006-12-04 02:32:45 UTC (rev 3474)
+++ trunk/numpy/core/src/multiarraymodule.c	2006-12-04 20:32:39 UTC (rev 3475)
@@ -2486,25 +2486,32 @@
 		return (PyObject *)ret;
 	}
 
+        /* Creates new reference op2 */
 	if ((op2=(PyAO *)_check_axis(op, &axis, 0))==NULL) return NULL;
-
+        
 	/* Determine if we should use new algorithm or not */
 	if (op2->descr->f->argsort[which] != NULL) {
-		return _new_argsort(op2, axis, which);
+		ret = _new_argsort(op2, axis, which);
+                Py_DECREF(op2);
+                return ret;
 	}
 
+        op = NULL;
 	if ((which != PyArray_QUICKSORT) || op2->descr->f->compare == NULL) {
 		PyErr_SetString(PyExc_TypeError,
 				"requested sort not available for type");
+                Py_DECREF(op2);
 		goto fail;
 	}
 
+        /* ap will contain the reference to op2 */
 	SWAPAXES(ap, op2);
 
 	op = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)ap,
 							   PyArray_NOTYPE,
 							   1, 0);
 
+        Py_DECREF(ap);
 	if (op == NULL) return NULL;
 
 	ret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,
@@ -2538,7 +2545,7 @@
 	return (PyObject *)op;
 
  fail:
-	Py_XDECREF(ap);
+	Py_XDECREF(op);
 	Py_XDECREF(ret);
 	return NULL;
 



More information about the Numpy-svn mailing list