[vtkusers] segmentation fault in vtkPythonUtil.cxx, proposed patch

David Gobbi dgobbi at imaging.robarts.ca
Tue Mar 11 10:29:25 EST 2003


Hi Henner,

Thanks for investigating this.  I wasn't able to use your patch file
because it is corrupted (it has some garbage in the middle).  Also
the PyObject_Del and PyObject_New are not available in python-1.5.2,
and I'm not ready to drop support for 1.5.2 quite yet.

Could you change the PyObject_Del and PyObject_New back to
PyMem_DEL and PyObject_NEW and then email me your fixed copy
of vtkPythonUtil.cxx (I.e. not a patch, but the file itself?)

Thanks,
 - David

-- 
  David Gobbi, MSc                dgobbi at imaging.robarts.ca
  Advanced Imaging Research Group
  Robarts Research Institute, University of Western Ontario

On Tue, 11 Mar 2003, Henner Eisen (FI) wrote:

> Hi,
>
> when trying to build VTK 4.2 on SuSE 8.1 using a customized
> python-2.2.1 installtion, I got segfaults whenever running a
> vtkpython related test. This bug is not triggered
> when building VTK with the SuSE-provided python (also 2.2.1).
>
> Running vtkpython under gdb and loading the Cone.py tutorial file yields:
>
>   Program received signal SIGSEGV, Segmentation fault.
>   [Switching to Thread 1024 (LWP 28698)]
>   0x413e96a1 in chunk_free () from /lib/libc.so.6
>   (gdb) where
>   #0  0x413e96a1 in chunk_free () from /lib/libc.so.6
>   #1  0x413e95f6 in free () from /lib/libc.so.6
>   #2  0x41a3bbc5 in PyVTKObject_PyDelete (self=0x418b3410)
>       at /data/tmp/eis/VTK-4.2.1-GLpy/Common/vtkPythonUtil.cxx:396
>   ...
>
> It seems that the problem is caused by incosistent use of
> python memory management functions. Memory is allocated by means
> of PyObject_NEW(), but freed by means of PyMem_DEL().
> I think python objects allocated by PyObject_NEW() must be freed
> consistently by PyObject_DEL(). Our custumized python installation
> was configured with the '--with-pymalloc' option, which is probably
> the reason why the bug is not triggered with the SuSE-provided
> python interpreter.
>
> Anyway, the following patch (against VTK 4.2.1, but 4.0 seems to
> suffer from the same problem) fixes the symptom.
> (It also uses the slower, but more diagnostic-friendly _New/_Del
> variants instead of the _NEW/_DEL variants of the Python
> memory functions). I hope I did not neglect any side effects,
> somebody familar with vtkPythonUtil.cxx should review this.
>
> Henner
>
>
>
> --- Common/vtkPythonUtil.cxx.old        2003-03-11 11:19:15.000000000 +0100
> +++ Common/vtkPythonUtil.cxx    2003-03-11 12:03:55.000000000 +0100
> @@ -381,7 +381,7 @@
>     vtkPythonDeleteObjectFromHash((PyObject *)this->Self);
>     Py_DECREF((PyObject *)this->Self->vtk_class);
>     Py_DECREF(this->Self->vtk_dict);
> -  PyMem_DEL(this->Self);
> +  PyObject_Del(this->Self);
>   }
>
>   //--------------------------------------------------------------------
> @@ -393,7 +393,7 @@
>     vtkPythonDeleteObjectFromHash((PyObject *)self);
>     Py_DECREF((PyObject *)self->vtk_class);
>     Py_DECREF(self->vtk_dict);
> -  PyMem_DEL(self);
> +  PyObject_Del(self);
>   }
>
>   //--------------------------------------------------------------------
> @@ -446,7 +446,7 @@
>                       "this is an abstract class and cannot be instantiated");
>       return 0;
>       }
> -  PyVTKObject *self = PyObject_NEW(PyVTKObject, &PyVTKObjectType);
> +  PyVTKObject *self = PyObject_New(PyVTKObject, &PyVTKObjectType);
>     self->vtk_ptr = ptr;
>     PyObject *cls = NULL;
>     vtkstd::map<vtkstd::string, PyObject*>::iterator i =
> @@ -703,7 +703,7 @@
>     Py_XDECREF(self->vtk_module);
>     Py_XDECREF(self->vtk_doc);
>
> -  PyMem_DEL(self);
> +  PyObject_Del(self);
>   }
>
>   //--------------------------------------------------------------------
> @@ -871,7 +871,7 @@
>       }
>     else
>       {
> -    PyVTKClass *class_self = PyObject_NEW(PyVTKClass, &PyVTKClassType);
> +    PyVTKClass *class_self = PyObject_New(PyVTKClass, &PyVTKClassType);
>       self = (PyObject *)class_self;
>
>       if (base)
> @@ -972,7 +972,7 @@
>         return NULL;
>         }
>
> -    newclass = PyObject_NEW(PyVTKClass, &PyVTKClassType);
> +    newclass = PyObject_New(PyVTKClass, &PyVTKClassType);
>
>       Py_INCREF(bases);
>       Py_INCREF(attributes);
> @@ -1123,7 +1123,7 @@
>     self->vtk_ptr = NULL;
>     Py_XDECREF(self->vtk_name);
>     Py_XDECREF(self->vtk_doc);
> -  PyMem_DEL(self);
> +  PyObject_Del(self);
>   }
>
>   //--------------------------------------------------------------------
> @@ -1161,7 +1161,7 @@
>   PyObject *PyVTKSpecialObject_New(void *ptr, PyMethodDef *methods,
>                                    char *classname, char *docstring[])
>   {
> -  PyVTKSpecialObject *self = PyObject_NEW(PyVTKSpecialObject,
> +  PyVTKSpecialObject *self = PyObject_New(PyVTKSpecialObject,
>                                             &PyVTKSpecialObjectType);
>     self->vtk_ptr = ptr;
>     self->vtk_methods = methods;
> eis at pc021371:VTK-4.2.1-GLpy less ../gdb.out
> eis at pc021371:VTK-4.2.1-GLpy cat py.diff
> --- Common/vtkPythonUtil.cxx.old        2003-03-11 11:19:15.000000000 +0100
> +++ Common/vtkPythonUtil.cxx    2003-03-11 12:03:55.000000000 +0100
> @@ -381,7 +381,7 @@
>     vtkPythonDeleteObjectFromHash((PyObject *)this->Self);
>     Py_DECREF((PyObject *)this->Self->vtk_class);
>     Py_DECREF(this->Self->vtk_dict);
> -  PyMem_DEL(this->Self);
> +  PyObject_Del(this->Self);
>   }
>
>   //--------------------------------------------------------------------
> @@ -393,7 +393,7 @@
>     vtkPythonDeleteObjectFromHash((PyObject *)self);
>     Py_DECREF((PyObject *)self->vtk_class);
>     Py_DECREF(self->vtk_dict);
> -  PyMem_DEL(self);
> +  PyObject_Del(self);
>   }
>
>   //--------------------------------------------------------------------
> @@ -446,7 +446,7 @@
>                       "this is an abstract class and cannot be instantiated");
>       return 0;
>       }
> -  PyVTKObject *self = PyObject_NEW(PyVTKObject, &PyVTKObjectType);
> +  PyVTKObject *self = PyObject_New(PyVTKObject, &PyVTKObjectType);
>     self->vtk_ptr = ptr;
>     PyObject *cls = NULL;
>     vtkstd::map<vtkstd::string, PyObject*>::iterator i =
> @@ -703,7 +703,7 @@
>     Py_XDECREF(self->vtk_module);
>     Py_XDECREF(self->vtk_doc);
>
> -  PyMem_DEL(self);
> +  PyObject_Del(self);
>   }
>
>   //--------------------------------------------------------------------
> @@ -871,7 +871,7 @@
>       }
>     else
>       {
> -    PyVTKClass *class_self = PyObject_NEW(PyVTKClass, &PyVTKClassType);
> +    PyVTKClass *class_self = PyObject_New(PyVTKClass, &PyVTKClassType);
>       self = (PyObject *)class_self;
>
>       if (base)
> @@ -972,7 +972,7 @@
>         return NULL;
>         }
>
> -    newclass = PyObject_NEW(PyVTKClass, &PyVTKClassType);
> +    newclass = PyObject_New(PyVTKClass, &PyVTKClassType);
>
>       Py_INCREF(bases);
>       Py_INCREF(attributes);
> @@ -1123,7 +1123,7 @@
>     self->vtk_ptr = NULL;
>     Py_XDECREF(self->vtk_name);
>     Py_XDECREF(self->vtk_doc);
> -  PyMem_DEL(self);
> +  PyObject_Del(self);
>   }
>
>   //--------------------------------------------------------------------
> @@ -1161,7 +1161,7 @@
>   PyObject *PyVTKSpecialObject_New(void *ptr, PyMethodDef *methods,
>                                    char *classname, char *docstring[])
>   {
> -  PyVTKSpecialObject *self = PyObject_NEW(PyVTKSpecialObject,
> +  PyVTKSpecialObject *self = PyObject_New(PyVTKSpecialObject,
>                                             &PyVTKSpecialObjectType);
>     self->vtk_ptr = ptr;
>     self->vtk_methods = methods;
>
>




More information about the vtkusers mailing list