Commits

Anonymous committed 52da926

safer code

  • Participants
  • Parent commits 98e7b06

Comments (0)

Files changed (1)

carraywrap/carraywrapmodule.c

   printf("'%s' called\n", __func__);
 #endif
   self = (CArrayWrap *)type->tp_alloc(type, 0);
+  if (self == NULL){
+    return NULL;
+  }
   self->ndim = 0;
-  self->nparray = NULL;
+  self->nparray = Py_BuildValue("");
+  if (self->nparray == NULL){
+    Py_DECREF(self);
+    return NULL;
+  }
   return (PyObject *)self;
 }
 
 static int
 CArrayWrap_init(CArrayWrap *self, PyObject *args, PyObject *kwds)
 {
-  PyObject *obj;
+  PyObject *obj, *tmp;
   int i, elemnum;
 #ifdef CARRAYWRAP_VERBOSE
   printf("'%s' called\n", __func__);
     break;
   }
 
+  tmp = self->nparray;
   self->nparray =
     PyArray_SimpleNewFromData( self->ndim, self->dims, NPY_LONG,
 			       (void *)self->data );
     goto fail;
   }
   Py_INCREF(self->nparray);
+  Py_XDECREF(tmp);
 
 /* #define CARRAYWRAP_TEST_OWNDATA_FAIL */
 #ifndef CARRAYWRAP_TEST_OWNDATA_FAIL