Browse Source

fix memory leaks

David Rose 17 years ago
parent
commit
b9cb301df9
1 changed files with 6 additions and 4 deletions
  1. 6 4
      panda/src/event/pythonTask.cxx

+ 6 - 4
panda/src/event/pythonTask.cxx

@@ -21,7 +21,7 @@
 TypeHandle PythonTask::_type_handle;
 TypeHandle PythonTask::_type_handle;
 
 
 #ifndef CPPPARSER
 #ifndef CPPPARSER
-IMPORT_THIS struct Dtool_PyTypedObject Dtool_TypedReferenceCount;
+IMPORT_THIS struct Dtool_PyTypedObject Dtool_PythonTask;
 #endif
 #endif
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -147,10 +147,10 @@ get_args() {
       PyTuple_SET_ITEM(with_task, i, item);
       PyTuple_SET_ITEM(with_task, i, item);
     }
     }
 
 
+    this->ref();
     PyObject *self = 
     PyObject *self = 
-      DTool_CreatePyInstanceTyped(this, Dtool_TypedReferenceCount,
+      DTool_CreatePyInstanceTyped(this, Dtool_PythonTask,
                                   true, false, get_type_index());
                                   true, false, get_type_index());
-    Py_INCREF(self);
     PyTuple_SET_ITEM(with_task, num_args, self);
     PyTuple_SET_ITEM(with_task, num_args, self);
     return with_task;
     return with_task;
 
 
@@ -565,10 +565,12 @@ call_owner_method(const char *method_name) {
 void PythonTask::
 void PythonTask::
 call_function(PyObject *function) {
 call_function(PyObject *function) {
   if (function != Py_None) {
   if (function != Py_None) {
+    this->ref();
     PyObject *self = 
     PyObject *self = 
-      DTool_CreatePyInstanceTyped(this, Dtool_TypedReferenceCount,
+      DTool_CreatePyInstanceTyped(this, Dtool_PythonTask,
                                   true, false, get_type_index());
                                   true, false, get_type_index());
     PyObject *args = PyTuple_Pack(1, self);
     PyObject *args = PyTuple_Pack(1, self);
+    Py_DECREF(self);
     
     
     PyObject *result = PyObject_CallObject(function, args);
     PyObject *result = PyObject_CallObject(function, args);
     Py_XDECREF(result);
     Py_XDECREF(result);