From 31aa1cdfeeb11157162567eee9e9df5bec1843f9 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 6 May 2011 09:20:06 +0000 Subject: [PATCH] Fixed Coverity reported issues. CID 11389: Resource leak in object (CTOR_DTOR_LEAK) Allocating memory by calling "new bsp::VBSPData". Assigning: "this->bsp_data" = "new bsp::VBSPData". The constructor allocates field "bsp_data" of "struct bsp::VBSPReader" but the destructor and whatever functions it calls do not free it. --- src/osgPlugins/bsp/VBSPData.h | 5 +++-- src/osgPlugins/bsp/VBSPReader.cpp | 2 +- src/osgPlugins/bsp/VBSPReader.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/osgPlugins/bsp/VBSPData.h b/src/osgPlugins/bsp/VBSPData.h index f1617efdb..51e932acf 100644 --- a/src/osgPlugins/bsp/VBSPData.h +++ b/src/osgPlugins/bsp/VBSPData.h @@ -162,7 +162,7 @@ struct DisplacedVertex }; -class VBSPData +class VBSPData : public osg::Referenced { protected: @@ -211,10 +211,11 @@ protected: typedef std::vector< osg::ref_ptr > StateSetList; StateSetList state_set_list; + virtual ~VBSPData(); + public: VBSPData(); - virtual ~VBSPData(); void addEntity(std::string & newEntity); const int getNumEntities() const; diff --git a/src/osgPlugins/bsp/VBSPReader.cpp b/src/osgPlugins/bsp/VBSPReader.cpp index 420a4ed89..549a14c9a 100644 --- a/src/osgPlugins/bsp/VBSPReader.cpp +++ b/src/osgPlugins/bsp/VBSPReader.cpp @@ -1055,7 +1055,7 @@ void VBSPReader::createScene() { // Get the entity entityText = bsp_data->getEntity(i); - currentEntity = new VBSPEntity(entityText, bsp_data); + currentEntity = new VBSPEntity(entityText, bsp_data.get()); // See if the entity is visible if (currentEntity->isVisible()) diff --git a/src/osgPlugins/bsp/VBSPReader.h b/src/osgPlugins/bsp/VBSPReader.h index 16469de7e..8e1c8d0b9 100644 --- a/src/osgPlugins/bsp/VBSPReader.h +++ b/src/osgPlugins/bsp/VBSPReader.h @@ -233,7 +233,7 @@ protected: std::string map_name; - VBSPData * bsp_data; + osg::ref_ptr bsp_data; osg::ref_ptr root_node;