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

Henner Eisen (FI) eis at germanlloyd.org
Tue Mar 11 09:37:07 EST 2003


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;

-- 

_______________________________________________________________________________
|                                        url    :  http://www.germanlloyd.org /
| Dipl.-Math. Henner Eisen        __     Address:                            /
| eis at germanlloyd.org          G /  \ L   Germanischer Lloyd                /
| phone:    +49-40-36149-985   -+----+-   Vorsetzen 32       P.O.Box 111606/
| fax  :    +49-40-36149-7320    \__/     20459 Hamburg      20416 Hamburg/
|                                         Germany                        /
|_______________________________________________________________________/
 
 
 
 
****************************************************
 
 
Beachten Sie:  Wir moechten Sie informieren, dass die E-Mail-Adresse des Germanischen Lloyd sowie unsere Web-Adresse mit Wirkung vom 1. Maerz 2003 auf den Namen gl-group.com umgestellt wurde.
 
 
Dies bedeutet, dass die bisherige Adresse Kurzzeichen at germanlloyd.org durch die neue Adresse Kurzzeichen at gl-group.com ersetzt wird. Die Homepage des GL ist kuenftig uber die Adresse 'http://www.gl-group.com' aufrufbar. Die bisher verwendeten Adressen bleiben fur eine Uebergangsfrist erreichbar.
 
 
**************************************************** 
 
Please notice: We would like to inform you that the e-mail address of Germanischer Lloyd as well as our internet address had been changed to  gl-group.com with effect from 1st March 2003.
 
 
This means that the previous address shortmark at germanlloyd.org will be replaced by shortmark at gl-group.com. From now on the GL homepage can be accessed at the address 'http://www.gl-group.com'. The old addresses remain valid for a transitional period.
 

 
 
****************************************************
 
 
 
 
This e-mail contains confidential information for the exclusive attention of the intended addressee. Any access of third parties to this e-mail is unauthorised. Any use of this e-mail by unintended recipients such as copying, distribution, disclosure etc. is prohibited and may be unlawful. When addressed to our clients the content of this e-mail is subject to the General Terms and Conditions of GL's Group of Companies applicable at the date of this e-mail.  
 
GL's Group of Companies does not warrant and/or guarantee that this message at the moment of receipt is authentic, correct and its communication free of errors, interruption etc. 
 

 



More information about the vtkusers mailing list