Second attempt to fix a null pointer reference in deallocators of
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Sun, 26 Jul 2009 20:20:25 +0000 (20:20 +0000)
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Sun, 26 Jul 2009 20:20:25 +0000 (20:20 +0000)
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.

27 files changed:
source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.cpp
source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.cpp
source/blender/freestyle/intern/python/BPy_Interface0D.cpp
source/blender/freestyle/intern/python/BPy_Interface1D.cpp
source/blender/freestyle/intern/python/BPy_Iterator.cpp
source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp
source/blender/freestyle/intern/python/BPy_StrokeShader.cpp
source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp
source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp
source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DDouble.cpp
source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DEdgeNature.cpp
source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DFloat.cpp
source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DId.cpp
source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DMaterial.cpp
source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DUnsigned.cpp
source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec2f.cpp
source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec3f.cpp
source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVectorViewShape.cpp
source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DViewShape.cpp
source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DDouble.cpp
source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DEdgeNature.cpp
source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DFloat.cpp
source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DUnsigned.cpp
source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVec2f.cpp
source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVec3f.cpp
source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVectorViewShape.cpp
source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVoid.cpp

index 71504903f8101727e0d475816670246de2a5cdbd..7721bc1ba0d74e1f5405e901017aaf3989167cb8 100644 (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);
 }
 
index 1f601d604124fbe15360675be2561e9550233a80..80195ed0a2089481f94d3fe17d2b2163e583dedb 100644 (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);
 }
 
index fb8c27c42051690eb5187a59429f18c2c69348b7..11d7cec7058fdaa2b116dfc9d4c30fd889ac4c85 100644 (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);
 }
index b6a6501c540f5fc79a17afd7f72c995d131e060a..c6d6e75d897fbae103f836328d64b42365c29abc 100644 (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);
 }
index 5c19dfd29acdfb97e6e983774ac49b34a95df6b1..3356325c92fa3a5192a82351b2578e65c9fed4cf 100644 (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);
 }
 
index 8f20e740580ea221a3d14cdb1e20af83adba0fa4..c603acac9b487504a778c788b7fec975de7f4d58 100644 (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);
 }
index f18620888f0bfb0a4c6b1ac2b95d3e90f6e7bb2b..c53f1e7d88841c8f93250519f6f1a046d34a952d 100644 (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);
 }
 
index 5f3312a18012f860cfdb1a8534361c4db8d3b391..8dc3b12a915c4a6c5c7a7897d95df41f8b1fa692 100644 (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);
 }
 
index 7bf4cfbbc6d4e2477d0a9787aedab64bf5af8a7b..18714095ef179a1ce50a1225cea252ca2a53236d 100644 (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);
 }
 
index cfc4bb24a56319a75ceb588eb9ba1b122fffad72..3d0eadfa9a3dfd7ba754a515f76ccc164d6040d9 100644 (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);
 }
 
index ac5b1257167dc5f206a38e982412f0ea70c1c90d..543d6dc57a75467da1461b810dc055809514ebda 100644 (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);
 }
 
index 13285bdcf88d89ed16fc94559f02c63f3b0cf03f..949a88a49af716933b37f9bd403dd1f3f3c444cc 100644 (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);
 }
 
index 15863eb3600a99b98ab63bbc55b2f02e10cb1cf4..1041f1053de609c72b39003be28a5ff6fcbf05b3 100644 (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);
 }
 
index bbb7e2d61a21ebe15d31c66232d2e2267b9903eb..64b4d53fe2ef6078aabff646c86da9753c014dfc 100644 (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);
 }
 
index 1b8535318af01d4e898cea3013987b39c9db0a2e..b0ecbc79cd2364d702cf37a5158d7ab7e4bcd069 100644 (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);
 }
 
index a2bda09180aff1a830fc5e02b0e37cb552920fc7..946210ee3813c87e83cea5c72193e4c7bea6fee7 100644 (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);
 }
 
index b484d872627b7a27948543a3b8ae3e2b5e484d6b..d3d0a6593ca5b340c706c062f4bb49a3af0fb4df 100644 (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);
 }
 
index 9640bf23e438d9190c24765deabd7fc67925a399..de77cdd686b6caa9fd48f3874f50f1ed624b40fc 100644 (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);
 }
 
index d8be0411c9e9b8f33918cb09038a30c808230e2e..2fe1e61dcf36b0708330496b5f75044097a4feef 100644 (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);
 }
 
index 89d79e0b83fbfee0e6a822442d34c46e67f01da7..17949073949c0ec25cba0bc9b68812dcdccd6ca7 100644 (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);
 }
 
index 7723be839a487c786e0b1ed0dc2a8feea15132a5..e704eebc8be3ba012c6246146d5047a99822be6c 100644 (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);
 }
 
index 2a8d8f9ec75d63b60e47a4029369b90b740dba82..362965542132fa1f87ec6e68923437d307ea02ce 100644 (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);
 }
 
index 44bf1c5d563f1568b8572b1148d5426426072d0a..18da07c5bfb5900a698ea333587d2aabcfe23964 100644 (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);
 }
 
index cb4698b1c509f2a9e4df00444f88b8f9238d6c43..06c17d0f63502ecb8d852200df674decfab53881 100644 (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);
 }
 
index 0d4ce8c6cf16068d616160e33e2a488c85e0d11f..2fe32c1c3115f77492ad8385daa236df2c38b239 100644 (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);
 }
 
index a79b70e4593525098041eab4d8070bcd89c552f7..5b86ea1f4cac5a64563e0d354f6ca74f15981f12 100644 (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);
 }
 
index 4c081b8ad6400e0383cfc2129e55b75156c4604a..ff588a9f3b831558401f47d512c5fe99f769f7e8 100644 (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);
 }