Second attempt to fix a null pointer reference in deallocators of

built-in types (the first was in revision 21877).  When an exception
has raised within from the __init__ method of a user-defined class
derived from a built-in type (e.g., UnaryPredicate0D and
BinaryPredicate1D), some member variables of the base type are
left uninitialized, leading to a null pointer reference in the
"__dealloc__" function in the base type.  To avoid this, pointer
checking was added in the deallocators of those built-in types that
can be used to define a subclass by a user.
This commit is contained in:
2009-07-26 20:20:25 +00:00
parent 69853d3e40
commit 52f639277b
27 changed files with 51 additions and 27 deletions

View File

@@ -133,7 +133,8 @@ int BinaryPredicate0D___init__(BPy_BinaryPredicate0D *self, PyObject *args, PyOb
void BinaryPredicate0D___dealloc__(BPy_BinaryPredicate0D* self)
{
delete self->bp0D;
if (self->bp0D)
delete self->bp0D;
self->ob_type->tp_free((PyObject*)self);
}

View File

@@ -164,7 +164,8 @@ int BinaryPredicate1D___init__(BPy_BinaryPredicate1D *self, PyObject *args, PyOb
void BinaryPredicate1D___dealloc__(BPy_BinaryPredicate1D* self)
{
delete self->bp1D;
if (self->bp1D)
delete self->bp1D;
self->ob_type->tp_free((PyObject*)self);
}

View File

@@ -189,7 +189,7 @@ int Interface0D___init__(BPy_Interface0D *self, PyObject *args, PyObject *kwds)
void Interface0D___dealloc__(BPy_Interface0D* self)
{
if( self->if0D->py_if0D )
if( self->if0D && self->if0D->py_if0D )
delete self->if0D;
self->ob_type->tp_free((PyObject*)self);
}

View File

@@ -204,7 +204,7 @@ int Interface1D___init__(BPy_Interface1D *self, PyObject *args, PyObject *kwds)
void Interface1D___dealloc__(BPy_Interface1D* self)
{
if( self->if1D->py_if1D )
if( self->if1D && self->if1D->py_if1D )
delete self->if1D;
self->ob_type->tp_free((PyObject*)self);
}

View File

@@ -193,7 +193,8 @@ PyMODINIT_FUNC Iterator_Init( PyObject *module )
void Iterator___dealloc__(BPy_Iterator* self)
{
delete self->it;
if (self->it)
delete self->it;
self->ob_type->tp_free((PyObject*)self);
}

View File

@@ -208,7 +208,7 @@ int StrokeAttribute___init__(BPy_StrokeAttribute *self, PyObject *args, PyObject
void StrokeAttribute___dealloc__(BPy_StrokeAttribute* self)
{
if( self->sa->py_sa )
if( self->sa && self->sa->py_sa )
delete self->sa;
self->ob_type->tp_free((PyObject*)self);
}

View File

@@ -266,7 +266,8 @@ int StrokeShader___init__(BPy_StrokeShader *self, PyObject *args, PyObject *kwds
void StrokeShader___dealloc__(BPy_StrokeShader* self)
{
delete self->ss;
if (self->ss)
delete self->ss;
self->ob_type->tp_free((PyObject*)self);
}

View File

@@ -144,7 +144,8 @@ int UnaryPredicate0D___init__(BPy_UnaryPredicate0D *self, PyObject *args, PyObje
void UnaryPredicate0D___dealloc__(BPy_UnaryPredicate0D* self)
{
delete self->up0D;
if (self->up0D)
delete self->up0D;
self->ob_type->tp_free((PyObject*)self);
}

View File

@@ -186,7 +186,8 @@ int UnaryPredicate1D___init__(BPy_UnaryPredicate1D *self, PyObject *args, PyObje
void UnaryPredicate1D___dealloc__(BPy_UnaryPredicate1D* self)
{
delete self->up1D;
if (self->up1D)
delete self->up1D;
self->ob_type->tp_free((PyObject*)self);
}

View File

@@ -197,7 +197,8 @@ int UnaryFunction0DDouble___init__(BPy_UnaryFunction0DDouble* self)
void UnaryFunction0DDouble___dealloc__(BPy_UnaryFunction0DDouble* self)
{
delete self->uf0D_double;
if (self->uf0D_double)
delete self->uf0D_double;
UnaryFunction0D_Type.tp_dealloc((PyObject*)self);
}

View File

@@ -140,7 +140,8 @@ int UnaryFunction0DEdgeNature___init__(BPy_UnaryFunction0DEdgeNature* self)
void UnaryFunction0DEdgeNature___dealloc__(BPy_UnaryFunction0DEdgeNature* self)
{
delete self->uf0D_edgenature;
if (self->uf0D_edgenature)
delete self->uf0D_edgenature;
UnaryFunction0D_Type.tp_dealloc((PyObject*)self);
}

View File

@@ -169,7 +169,8 @@ int UnaryFunction0DFloat___init__(BPy_UnaryFunction0DFloat* self)
void UnaryFunction0DFloat___dealloc__(BPy_UnaryFunction0DFloat* self)
{
delete self->uf0D_float;
if (self->uf0D_float)
delete self->uf0D_float;
UnaryFunction0D_Type.tp_dealloc((PyObject*)self);
}

View File

@@ -140,7 +140,8 @@ int UnaryFunction0DId___init__(BPy_UnaryFunction0DId* self)
void UnaryFunction0DId___dealloc__(BPy_UnaryFunction0DId* self)
{
delete self->uf0D_id;
if (self->uf0D_id)
delete self->uf0D_id;
UnaryFunction0D_Type.tp_dealloc((PyObject*)self);
}

View File

@@ -140,7 +140,8 @@ int UnaryFunction0DMaterial___init__(BPy_UnaryFunction0DMaterial* self)
void UnaryFunction0DMaterial___dealloc__(BPy_UnaryFunction0DMaterial* self)
{
delete self->uf0D_material;
if (self->uf0D_material)
delete self->uf0D_material;
UnaryFunction0D_Type.tp_dealloc((PyObject*)self);
}

View File

@@ -140,7 +140,8 @@ int UnaryFunction0DUnsigned___init__(BPy_UnaryFunction0DUnsigned* self)
void UnaryFunction0DUnsigned___dealloc__(BPy_UnaryFunction0DUnsigned* self)
{
delete self->uf0D_unsigned;
if (self->uf0D_unsigned)
delete self->uf0D_unsigned;
UnaryFunction0D_Type.tp_dealloc((PyObject*)self);
}

View File

@@ -146,7 +146,8 @@ int UnaryFunction0DVec2f___init__(BPy_UnaryFunction0DVec2f* self)
void UnaryFunction0DVec2f___dealloc__(BPy_UnaryFunction0DVec2f* self)
{
delete self->uf0D_vec2f;
if (self->uf0D_vec2f)
delete self->uf0D_vec2f;
UnaryFunction0D_Type.tp_dealloc((PyObject*)self);
}

View File

@@ -140,7 +140,8 @@ int UnaryFunction0DVec3f___init__(BPy_UnaryFunction0DVec3f* self)
void UnaryFunction0DVec3f___dealloc__(BPy_UnaryFunction0DVec3f* self)
{
delete self->uf0D_vec3f;
if (self->uf0D_vec3f)
delete self->uf0D_vec3f;
UnaryFunction0D_Type.tp_dealloc((PyObject*)self);
}

View File

@@ -140,7 +140,8 @@ int UnaryFunction0DVectorViewShape___init__(BPy_UnaryFunction0DVectorViewShape*
void UnaryFunction0DVectorViewShape___dealloc__(BPy_UnaryFunction0DVectorViewShape* self)
{
delete self->uf0D_vectorviewshape;
if (self->uf0D_vectorviewshape)
delete self->uf0D_vectorviewshape;
UnaryFunction0D_Type.tp_dealloc((PyObject*)self);
}

View File

@@ -146,7 +146,8 @@ int UnaryFunction0DViewShape___init__(BPy_UnaryFunction0DViewShape* self)
void UnaryFunction0DViewShape___dealloc__(BPy_UnaryFunction0DViewShape* self)
{
delete self->uf0D_viewshape;
if (self->uf0D_viewshape)
delete self->uf0D_viewshape;
UnaryFunction0D_Type.tp_dealloc((PyObject*)self);
}

View File

@@ -237,7 +237,8 @@ int UnaryFunction1DDouble___init__(BPy_UnaryFunction1DDouble* self, PyObject *ar
void UnaryFunction1DDouble___dealloc__(BPy_UnaryFunction1DDouble* self)
{
delete self->uf1D_double;
if (self->uf1D_double)
delete self->uf1D_double;
UnaryFunction1D_Type.tp_dealloc((PyObject*)self);
}

View File

@@ -157,7 +157,8 @@ int UnaryFunction1DEdgeNature___init__(BPy_UnaryFunction1DEdgeNature* self, PyOb
}
void UnaryFunction1DEdgeNature___dealloc__(BPy_UnaryFunction1DEdgeNature* self)
{
delete self->uf1D_edgenature;
if (self->uf1D_edgenature)
delete self->uf1D_edgenature;
UnaryFunction1D_Type.tp_dealloc((PyObject*)self);
}

View File

@@ -150,7 +150,8 @@ int UnaryFunction1DFloat___init__(BPy_UnaryFunction1DFloat* self, PyObject *args
}
void UnaryFunction1DFloat___dealloc__(BPy_UnaryFunction1DFloat* self)
{
delete self->uf1D_float;
if (self->uf1D_float)
delete self->uf1D_float;
UnaryFunction1D_Type.tp_dealloc((PyObject*)self);
}

View File

@@ -157,7 +157,8 @@ int UnaryFunction1DUnsigned___init__(BPy_UnaryFunction1DUnsigned* self, PyObject
}
void UnaryFunction1DUnsigned___dealloc__(BPy_UnaryFunction1DUnsigned* self)
{
delete self->uf1D_unsigned;
if (self->uf1D_unsigned)
delete self->uf1D_unsigned;
UnaryFunction1D_Type.tp_dealloc((PyObject*)self);
}

View File

@@ -163,7 +163,8 @@ int UnaryFunction1DVec2f___init__(BPy_UnaryFunction1DVec2f* self, PyObject *args
}
void UnaryFunction1DVec2f___dealloc__(BPy_UnaryFunction1DVec2f* self)
{
delete self->uf1D_vec2f;
if (self->uf1D_vec2f)
delete self->uf1D_vec2f;
UnaryFunction1D_Type.tp_dealloc((PyObject*)self);
}

View File

@@ -157,7 +157,8 @@ int UnaryFunction1DVec3f___init__(BPy_UnaryFunction1DVec3f* self, PyObject *args
}
void UnaryFunction1DVec3f___dealloc__(BPy_UnaryFunction1DVec3f* self)
{
delete self->uf1D_vec3f;
if (self->uf1D_vec3f)
delete self->uf1D_vec3f;
UnaryFunction1D_Type.tp_dealloc((PyObject*)self);
}

View File

@@ -171,7 +171,8 @@ int UnaryFunction1DVectorViewShape___init__(BPy_UnaryFunction1DVectorViewShape*
void UnaryFunction1DVectorViewShape___dealloc__(BPy_UnaryFunction1DVectorViewShape* self)
{
delete self->uf1D_vectorviewshape;
if (self->uf1D_vectorviewshape)
delete self->uf1D_vectorviewshape;
UnaryFunction1D_Type.tp_dealloc((PyObject*)self);
}

View File

@@ -172,7 +172,8 @@ int UnaryFunction1DVoid___init__(BPy_UnaryFunction1DVoid* self, PyObject *args)
void UnaryFunction1DVoid___dealloc__(BPy_UnaryFunction1DVoid* self)
{
delete self->uf1D_void;
if (self->uf1D_void)
delete self->uf1D_void;
UnaryFunction1D_Type.tp_dealloc((PyObject*)self);
}