[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [10787] trunk/blender/source/blender/ python/api2_2x: more memory leak fixes, though only a few are likely to happen

Campbell Barton cbarton at metavr.com
Sun May 27 23:33:49 CEST 2007


Revision: 10787
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bforge-svn&revision=10787
Author:   campbellbarton
Date:     2007-05-27 23:33:48 +0200 (Sun, 27 May 2007)

Log Message:
-----------
more memory leak fixes, though only a few are likely to happen

Modified Paths:
--------------
    trunk/blender/source/blender/python/api2_2x/Camera.c
    trunk/blender/source/blender/python/api2_2x/Curve.c
    trunk/blender/source/blender/python/api2_2x/Effect.c
    trunk/blender/source/blender/python/api2_2x/Font.c
    trunk/blender/source/blender/python/api2_2x/Group.c
    trunk/blender/source/blender/python/api2_2x/Image.c
    trunk/blender/source/blender/python/api2_2x/Ipo.c
    trunk/blender/source/blender/python/api2_2x/Ipocurve.c
    trunk/blender/source/blender/python/api2_2x/Lamp.c
    trunk/blender/source/blender/python/api2_2x/Lattice.c
    trunk/blender/source/blender/python/api2_2x/Material.c
    trunk/blender/source/blender/python/api2_2x/Mesh.c
    trunk/blender/source/blender/python/api2_2x/NMesh.c
    trunk/blender/source/blender/python/api2_2x/Scene.c
    trunk/blender/source/blender/python/api2_2x/Sound.c
    trunk/blender/source/blender/python/api2_2x/Text.c
    trunk/blender/source/blender/python/api2_2x/Texture.c
    trunk/blender/source/blender/python/api2_2x/gen_utils.c
    trunk/blender/source/blender/python/api2_2x/sceneSequence.c
    trunk/blender/source/blender/python/api2_2x/windowTheme.c

Modified: trunk/blender/source/blender/python/api2_2x/Camera.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Camera.c	2007-05-27 14:42:17 UTC (rev 10786)
+++ trunk/blender/source/blender/python/api2_2x/Camera.c	2007-05-27 21:33:48 UTC (rev 10787)
@@ -304,11 +304,12 @@
 		while( cam_iter ) {
 			pyobj = Camera_CreatePyObject( cam_iter );
 
-			if( !pyobj )
+			if( !pyobj ) {
+				Py_DECREF(cam_pylist);
 				return EXPP_ReturnPyObjError
 					( PyExc_MemoryError,
 					  "couldn't create Camera PyObject" );
-
+			}
 			PyList_SET_ITEM( cam_pylist, index, pyobj );
 
 			cam_iter = cam_iter->id.next;

Modified: trunk/blender/source/blender/python/api2_2x/Curve.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Curve.c	2007-05-27 14:42:17 UTC (rev 10786)
+++ trunk/blender/source/blender/python/api2_2x/Curve.c	2007-05-27 21:33:48 UTC (rev 10787)
@@ -481,7 +481,7 @@
 
 static PyObject *Curve_getControlPoint( BPy_Curve * self, PyObject * args )
 {
-	PyObject *liste = PyList_New( 0 );	/* return values */
+	PyObject *liste;
 	PyObject *item;
 
 	Nurb *ptrnurb;
@@ -498,7 +498,7 @@
 
 	/* if no nurbs in this curve obj */
 	if( !self->curve->nurb.first )
-		return liste;
+		return PyList_New( 0 );
 
 	/* walk the list of nurbs to find requested numcourbe */
 	ptrnurb = self->curve->nurb.first;
@@ -513,7 +513,8 @@
 	if( numpoint >= ptrnurb->pntsu )
 		return ( EXPP_ReturnPyObjError( PyExc_ValueError,
 						"point index out of range" ) );
-
+	
+	liste = PyList_New( 0 );
 	if( ptrnurb->bp ) {	/* if we are a nurb curve, you get 4 values */
 		for( i = 0; i < 4; i++ ) {
 			item = PyFloat_FromDouble( ptrnurb->bp[numpoint].vec[i] );

Modified: trunk/blender/source/blender/python/api2_2x/Effect.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Effect.c	2007-05-27 14:42:17 UTC (rev 10786)
+++ trunk/blender/source/blender/python/api2_2x/Effect.c	2007-05-27 21:33:48 UTC (rev 10787)
@@ -635,8 +635,7 @@
 					if (eff) {
 						return EffectCreatePyObject( eff, object_iter );
 					} else { /* didn't find any effect in the given position */
-						Py_INCREF(Py_None);
-						return Py_None;
+						Py_RETURN_NONE;
 					}
 				}
 

Modified: trunk/blender/source/blender/python/api2_2x/Font.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Font.c	2007-05-27 14:42:17 UTC (rev 10786)
+++ trunk/blender/source/blender/python/api2_2x/Font.c	2007-05-27 21:33:48 UTC (rev 10787)
@@ -136,11 +136,12 @@
 		while( vfont_iter ) {
 			pyobj = Font_CreatePyObject( vfont_iter );
 
-			if( !pyobj )
+			if( !pyobj ) {
+				Py_DECREF(vfontlist);
 				return ( EXPP_ReturnPyObjError
 					 ( PyExc_MemoryError,
 					   "couldn't create Object" ) );
-
+			}
 			PyList_SET_ITEM( vfontlist, index, pyobj );
 
 			vfont_iter = vfont_iter->id.next;

Modified: trunk/blender/source/blender/python/api2_2x/Group.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Group.c	2007-05-27 14:42:17 UTC (rev 10786)
+++ trunk/blender/source/blender/python/api2_2x/Group.c	2007-05-27 21:33:48 UTC (rev 10787)
@@ -426,11 +426,12 @@
 		while( group_iter ) {
 			pyobj = Group_CreatePyObject( group_iter );
 
-			if( !pyobj )
+			if( !pyobj ) {
+				Py_DECREF(grouplist);
 				return ( EXPP_ReturnPyObjError
 					 ( PyExc_MemoryError,
 					   "couldn't create Object" ) );
-
+			}
 			PyList_SET_ITEM( grouplist, index, pyobj );
 
 			group_iter = group_iter->id.next;

Modified: trunk/blender/source/blender/python/api2_2x/Image.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Image.c	2007-05-27 14:42:17 UTC (rev 10786)
+++ trunk/blender/source/blender/python/api2_2x/Image.c	2007-05-27 21:33:48 UTC (rev 10787)
@@ -389,7 +389,7 @@
 static PyObject *Image_getPixelF( BPy_Image * self, PyObject * args )
 {
 
-	PyObject *attr = PyList_New(4);
+	PyObject *attr;
 	ImBuf *ibuf= BKE_image_get_ibuf(self->image, NULL);
 	char *pixel;		/* image data */
 	int index;		/* offset into image data */
@@ -397,10 +397,6 @@
 	int y = 0;
 	int pixel_size = 4;	/* each pixel is 4 x 8-bits packed in unsigned int */
 	int i;
-
-	if (!attr)
-		return EXPP_ReturnPyObjError( PyExc_RuntimeError,
-				      "couldn't allocate memory for color list" );
 	
 	if( !PyArg_ParseTuple( args, "ii", &x, &y ) )
 		return EXPP_ReturnPyObjError( PyExc_TypeError,
@@ -425,6 +421,12 @@
 	   so we calc ourselves
 	 */
 
+	attr = PyList_New(4);
+	
+	if (!attr)
+		return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+				      "couldn't allocate memory for color list" );
+	
 	index = ( x + y * ibuf->x ) * pixel_size;
 
 	pixel = ( char * ) ibuf->rect;
@@ -815,11 +817,14 @@
 static PyObject *Image_getSize( BPy_Image * self )
 {
 	ImBuf *ibuf= BKE_image_get_ibuf(self->image, NULL);
-	PyObject *attr = PyList_New(2);
+	PyObject *attr;
 	
 	if( !ibuf )	/* didn't work */
 		return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 					      "couldn't load image data in Blender" );
+
+	attr = PyList_New(2);
+	
 	if( !attr )
 		return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 				      "couldn't get Image.size attribute" );

Modified: trunk/blender/source/blender/python/api2_2x/Ipo.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Ipo.c	2007-05-27 14:42:17 UTC (rev 10786)
+++ trunk/blender/source/blender/python/api2_2x/Ipo.c	2007-05-27 21:33:48 UTC (rev 10787)
@@ -1678,7 +1678,7 @@
 	struct BezTriple *ptrbt;
 	int num = 0, pos, i, j;
 	IpoCurve *icu;
-	PyObject *l = PyList_New( 0 ), *pyfloat;
+	PyObject *l, *pyfloat;
 
 	if( !PyArg_ParseTuple( args, "ii", &num, &pos ) )
 		return ( EXPP_ReturnPyObjError
@@ -1702,6 +1702,7 @@
 		return EXPP_ReturnPyObjError( PyExc_TypeError,
 					      "No bez triple" );
 
+	l = PyList_New( 0 );
 	for( i = 0; i < 3; i++ ) {
 		for( j = 0; j < 3; j++ ) {
 			pyfloat = PyFloat_FromDouble( ptrbt->vec[i][j] );

Modified: trunk/blender/source/blender/python/api2_2x/Ipocurve.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Ipocurve.c	2007-05-27 14:42:17 UTC (rev 10786)
+++ trunk/blender/source/blender/python/api2_2x/Ipocurve.c	2007-05-27 21:33:48 UTC (rev 10787)
@@ -645,7 +645,7 @@
 		po = BezTriple_CreatePyObject( bezt );
 		if( !po ) {
 			Py_DECREF( list );
-			return NULL;
+			return NULL; /* This is okay since the error is alredy set */
 		}
 		PyList_SET_ITEM( list, i, po );
 	}

Modified: trunk/blender/source/blender/python/api2_2x/Lamp.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Lamp.c	2007-05-27 14:42:17 UTC (rev 10786)
+++ trunk/blender/source/blender/python/api2_2x/Lamp.c	2007-05-27 21:33:48 UTC (rev 10787)
@@ -704,10 +704,12 @@
 		while( lamp_iter ) {
 			pyobj = Lamp_CreatePyObject( lamp_iter );
 
-			if( !pyobj )
+			if( !pyobj ) {
+				Py_DECREF(lamplist);
 				return ( EXPP_ReturnPyObjError
 					 ( PyExc_MemoryError,
-					   "couldn't create PyString" ) );
+					   "couldn't create PyLamp" ) );
+			}
 
 			PyList_SET_ITEM( lamplist, index, pyobj );
 

Modified: trunk/blender/source/blender/python/api2_2x/Lattice.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Lattice.c	2007-05-27 14:42:17 UTC (rev 10786)
+++ trunk/blender/source/blender/python/api2_2x/Lattice.c	2007-05-27 21:33:48 UTC (rev 10787)
@@ -235,11 +235,12 @@
 		while( lat_iter ) {
 			pyobj = Lattice_CreatePyObject( lat_iter );
 
-			if( !pyobj )
+			if( !pyobj ) {
+				Py_DECREF(latlist);
 				return ( EXPP_ReturnPyObjError
 					 ( PyExc_MemoryError,
 					   "couldn't create PyString" ) );
-
+			}
 			PyList_SET_ITEM( latlist, index, pyobj );
 
 			lat_iter = lat_iter->id.next;

Modified: trunk/blender/source/blender/python/api2_2x/Material.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Material.c	2007-05-27 14:42:17 UTC (rev 10786)
+++ trunk/blender/source/blender/python/api2_2x/Material.c	2007-05-27 21:33:48 UTC (rev 10787)
@@ -309,11 +309,12 @@
 		while( mat_iter ) {
 			pyobj = Material_CreatePyObject( mat_iter );
 
-			if( !pyobj )
+			if( !pyobj ) {
+				Py_DECREF(matlist);
 				return ( EXPP_ReturnPyObjError
 					 ( PyExc_MemoryError,
 					   "couldn't create PyObject" ) );
-
+			}
 			PyList_SET_ITEM( matlist, index, pyobj );
 
 			mat_iter = mat_iter->id.next;

Modified: trunk/blender/source/blender/python/api2_2x/Mesh.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Mesh.c	2007-05-27 14:42:17 UTC (rev 10786)
+++ trunk/blender/source/blender/python/api2_2x/Mesh.c	2007-05-27 21:33:48 UTC (rev 10787)
@@ -6200,14 +6200,17 @@
 		for( i = 0; i < PyList_Size( listObject ); i++ ) {
 			PyObject *attr = NULL;
 
-			if( !PyArg_Parse( PyList_GetItem( listObject, i ), "i", &num ) )
+			if( !PyArg_Parse( PyList_GetItem( listObject, i ), "i", &num ) ) {
+				Py_DECREF(tempVertexList);
 				return EXPP_ReturnPyObjError( PyExc_TypeError,
 							      "python list integer not parseable" );
+			}
 
-			if( num < 0 || num >= mesh->totvert )
+			if( num < 0 || num >= mesh->totvert ) {
+				Py_DECREF(tempVertexList);
 				return EXPP_ReturnPyObjError( PyExc_ValueError,
 							      "bad vertex index in list" );
-
+			}
 			dvert = mesh->dvert + num;
 			for( k = 0; k < dvert->totweight; k++ ) {
 				if( dvert->dw[k].def_nr == nIndex ) {

Modified: trunk/blender/source/blender/python/api2_2x/NMesh.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/NMesh.c	2007-05-27 14:42:17 UTC (rev 10786)
+++ trunk/blender/source/blender/python/api2_2x/NMesh.c	2007-05-27 21:33:48 UTC (rev 10787)
@@ -533,10 +533,12 @@
 
 			if( item )
 				PyList_SET_ITEM( vlcopy, i, item );
-			else
+			else {
+				Py_DECREF(vlcopy);
 				return EXPP_ReturnPyObjError
 					( PyExc_RuntimeError,
 					  "couldn't get vertex from a PyList" );
+			}
 		}
 	} else			/* create an empty vertex list */
 		vlcopy = PyList_New( 0 );
@@ -3808,14 +3810,16 @@
 		if( !
 		    ( PyArg_Parse
 		      ( ( PyList_GetItem( listObject, x ) ), "i",

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list