bugfix, memory leaks when getting particles and particle system loc/size/rot/life...
authorCampbell Barton <ideasman42@gmail.com>
Fri, 6 Jun 2008 11:00:32 +0000 (11:00 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 6 Jun 2008 11:00:32 +0000 (11:00 +0000)
source/blender/python/api2_2x/Object.c
source/blender/python/api2_2x/Particle.c

index 3db9664d47df98ed3e8ba4f043a2fea911dd4f44..45cce46d389688ce177117d17d7d8def42283bf0 100644 (file)
@@ -1056,10 +1056,12 @@ PyObject *Object_getParticleSys( BPy_Object * self ){
 /* fixme:  for(;;) */
        current = ParticleSys_CreatePyObject( blparticlesys, ob );
        PyList_Append(partsyslist,current);
+       Py_DECREF(current);
 
        while((blparticlesys = blparticlesys->next)){
                current = ParticleSys_CreatePyObject( blparticlesys, ob );
                PyList_Append(partsyslist,current);
+               Py_DECREF(current);
        }
 
        return partsyslist;
index f0a32db0623e446b02b435ed109bd09123945a78..95de9757b8709c3f81ea686535841ddcf480ff07 100644 (file)
@@ -854,7 +854,7 @@ static PyObject *Part_GetLoc( BPy_PartSys * self, PyObject * args ){
                                        return EXPP_ReturnPyObjError( PyExc_RuntimeError,
                                                        "Couldn't append item to PyList" );
                                }
-
+                               Py_DECREF(loc); /* PyList_Append increfs */
                                path++;
                        }
 
@@ -864,6 +864,7 @@ static PyObject *Part_GetLoc( BPy_PartSys * self, PyObject * args ){
                                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
                                                "Couldn't append item to PyList" );             
                        }
+                       Py_DECREF(seglist); /* PyList_Append increfs */
                }
 
                cache=psys->childcache;
@@ -885,7 +886,7 @@ static PyObject *Part_GetLoc( BPy_PartSys * self, PyObject * args ){
                                        return EXPP_ReturnPyObjError( PyExc_RuntimeError,
                                                        "Couldn't append item to PyList" );
                                }
-
+                               Py_DECREF(loc);/* PyList_Append increfs */
                                path++;
                        }
 
@@ -895,6 +896,7 @@ static PyObject *Part_GetLoc( BPy_PartSys * self, PyObject * args ){
                                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
                                                "Couldn't append item to PyList" );     
                        }
+                       Py_DECREF(seglist); /* PyList_Append increfs */
                }
                
        } else {
@@ -933,6 +935,7 @@ static PyObject *Part_GetLoc( BPy_PartSys * self, PyObject * args ){
                                        return EXPP_ReturnPyObjError( PyExc_RuntimeError,
                                                                "Couldn't append item to PyList" );
                                }
+                               Py_DECREF(loc);/* PyList_Append increfs */
                        }
                        else {
                                if ( all ){
@@ -941,6 +944,7 @@ static PyObject *Part_GetLoc( BPy_PartSys * self, PyObject * args ){
                                                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
                                                                        "Couldn't append item to PyList" );
                                        }
+                                       Py_DECREF(Py_None); /* PyList_Append increfs */
                                }
                        }
                }
@@ -985,6 +989,7 @@ static PyObject *Part_GetRot( BPy_PartSys * self, PyObject * args ){
                        if(psys_get_particle_state(ob,psys,i,&state,0)==0){
                                if ( all ){
                                        PyList_Append(partlist,Py_None);
+                                       Py_DECREF(Py_None); /* PyList_Append increfs */
                                        continue;
                                } else {
                                        continue;
@@ -1001,6 +1006,7 @@ static PyObject *Part_GetRot( BPy_PartSys * self, PyObject * args ){
                        if (id)
                                PyTuple_SetItem(loc,4,PyInt_FromLong(i));
                        PyList_Append(partlist,loc);
+                       Py_DECREF(loc); /* PyList_Append increfs */
                }
        }
        return partlist;
@@ -1060,9 +1066,11 @@ static PyObject *Part_GetSize( BPy_PartSys * self, PyObject * args ){
                                PyTuple_SetItem(tuple,0,PyFloat_FromDouble((double)size));
                                PyTuple_SetItem(tuple,1,PyInt_FromLong(i));
                                PyList_Append(partlist,tuple);
+                               Py_DECREF(tuple);
                        } else {
                                siz = PyFloat_FromDouble((double)size);
                                PyList_Append(partlist,siz);
+                               Py_DECREF(siz);
                        }
                }
        }
@@ -1125,9 +1133,11 @@ static PyObject *Part_GetAge( BPy_PartSys * self, PyObject * args ){
                                PyTuple_SetItem(tuple,0,PyFloat_FromDouble((double)life));
                                PyTuple_SetItem(tuple,1,PyInt_FromLong(i));
                                PyList_Append(partlist,tuple);
+                               Py_DECREF(tuple);
                        } else {
                                lif = PyFloat_FromDouble((double)life);
                                PyList_Append(partlist,lif);
+                               Py_DECREF(lif);
                        }
                }
        }