Fix memory leaks in GenericCAO, ShaderSource and Player classes
authorsapier <Sapier at GMX dot net>
Wed, 2 Jul 2014 21:33:18 +0000 (23:33 +0200)
committersapier <Sapier at GMX dot net>
Wed, 2 Jul 2014 21:33:18 +0000 (23:33 +0200)
src/content_cao.cpp
src/player.cpp
src/shader.cpp

index a05936d2c63bdf76bf8323d8d795a2192130c323..fe11d33da40c2ef4fbe177fdb0adbf97ffe2f9d5 100644 (file)
@@ -670,6 +670,7 @@ GenericCAO::~GenericCAO()
        {
                m_env->removePlayerName(m_name.c_str());
        }
+       removeFromScene(true);
 }
 
 core::aabbox3d<f32>* GenericCAO::getSelectionBox()
@@ -735,7 +736,7 @@ ClientActiveObject* GenericCAO::getParent()
 
 void GenericCAO::removeFromScene(bool permanent)
 {
-       if(permanent) // Should be true when removing the object permanently and false when refreshing (eg: updating visuals)
+       if((m_env != 0) && (permanent)) // Should be true when removing the object permanently and false when refreshing (eg: updating visuals)
        {
                for(std::vector<u16>::iterator ci = m_children.begin();
                                                ci != m_children.end(); ci++)
index f2ff590272e015c29e21a70695e66557f51fe949..40d403952bbbeac0b0c5822d8ef1803212dffc60 100644 (file)
@@ -100,6 +100,7 @@ Player::Player(IGameDef *gamedef):
 
 Player::~Player()
 {
+       clearHud();
 }
 
 // Horizontal acceleration (X and Z), Y direction is ignored
index f855a7fe3cd07eabc8585cf8a1ddc55655f5b7c9..ef15f29ba303dfb41dca6b7aeb4519ff832f5a8c 100644 (file)
@@ -383,13 +383,16 @@ ShaderSource::ShaderSource(IrrlichtDevice *device):
 
 ShaderSource::~ShaderSource()
 {
-       //m_shader_callback->drop();
-
        for (std::vector<IShaderConstantSetter*>::iterator iter = m_global_setters.begin();
                        iter != m_global_setters.end(); iter++) {
                delete *iter;
        }
        m_global_setters.clear();
+
+       if (m_shader_callback) {
+               m_shader_callback->drop();
+               m_shader_callback = NULL;
+       }
 }
 
 u32 ShaderSource::getShader(const std::string &name,