@@ -277,18 +277,20 @@ array_converter_as_arrays(PyArrayArrayConverterObject *self,
277277PyObject * res_item ;
278278if (item -> descr == NULL && policy == PRESERVE ) {
279279res_item = item -> object ;
280+ Py_INCREF (res_item );
280281 }
281282else {
282283res_item = (PyObject * )item -> array ;
283- }
284- Py_INCREF ( res_item );
285-
286- if (! subok ) {
287- Py_SETREF ( res_item , PyArray_EnsureArray (res_item ));
288- if ( res_item == NULL ) {
289- goto fail ;
284+ Py_INCREF ( res_item );
285+ if (! subok ) {
286+ /* PyArray_EnsureArray steals the reference... */
287+ res_item = PyArray_EnsureArray ( res_item );
288+ if (res_item == NULL ) {
289+ goto fail ;
290+ }
290291 }
291292 }
293+
292294if (PyTuple_SetItem (res ,i ,res_item )< 0 ) {
293295 gotofail ;
294296 }
@@ -331,9 +333,8 @@ array_converter_wrap(PyArrayArrayConverterObject *self,
331333 }
332334 }
333335
334- Py_INCREF (obj );
335-
336336if (self -> wrap == Py_None ) {
337+ Py_INCREF (obj );
337338if (ensure_scalar && PyArray_Check (obj )) {
338339/* Use PyArray_Return to convert to scalar when necessary */
339340return PyArray_Return ((PyArrayObject * )obj );
@@ -356,16 +357,21 @@ array_converter_wrap(PyArrayArrayConverterObject *self,
356357 * TODO: It might be best if this was always an array here. However,
357358 * for now scalars are common enough so convert them.
358359 */
359- if (!PyArray_Check (obj )) {
360- Py_SETREF (obj ,PyArray_FromAny (obj ,NULL ,0 ,0 ,0 ,NULL ));
361- if (obj == NULL ) {
360+ PyObject * arr ;
361+ if (PyArray_Check (obj )) {
362+ Py_INCREF (obj );
363+ arr = obj ;
364+ }
365+ else {
366+ arr = PyArray_FromAny (obj ,NULL ,0 ,0 ,0 ,NULL );
367+ if (arr == NULL ) {
362368return NULL ;
363369 }
364370 }
365371
366372/* There is no solution here for preferring a scalar return */
367- res = PyObject_CallOneArg (self -> wrap ,obj );
368- Py_DECREF (obj );
373+ res = PyObject_CallOneArg (self -> wrap ,arr );
374+ Py_DECREF (arr );
369375 }
370376
371377/*