Use unique_ptr to avoid memory leak in 3d model cache loading

PVS V773
This commit is contained in:
Marek Roszko 2022-02-05 14:37:51 -05:00
parent 1c77eb14d7
commit 36a5580f56
1 changed files with 3 additions and 6 deletions

View File

@ -25,6 +25,7 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#include <memory>
#include <wx/filename.h> #include <wx/filename.h>
#include <wx/log.h> #include <wx/log.h>
#include "plugins/3dapi/ifsg_api.h" #include "plugins/3dapi/ifsg_api.h"
@ -232,14 +233,12 @@ SGNODE* S3D::ReadCache( const char* aFileName, void* aPluginMgr,
return nullptr; return nullptr;
} }
SGNODE* np = new SCENEGRAPH( nullptr ); std::unique_ptr<SGNODE> np = std::make_unique<SCENEGRAPH>( nullptr );
OPEN_ISTREAM( file, aFileName ); OPEN_ISTREAM( file, aFileName );
if( file.fail() ) if( file.fail() )
{ {
delete np;
wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] failed to open file '%s'", wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] failed to open file '%s'",
__FILE__, __FUNCTION__, __LINE__, aFileName ); __FILE__, __FUNCTION__, __LINE__, aFileName );
@ -321,15 +320,13 @@ SGNODE* S3D::ReadCache( const char* aFileName, void* aPluginMgr,
if( !rval ) if( !rval )
{ {
delete np;
wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] problems encountered reading cache file '%s'", wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] problems encountered reading cache file '%s'",
__FILE__, __FUNCTION__, __LINE__, aFileName ); __FILE__, __FUNCTION__, __LINE__, aFileName );
return nullptr; return nullptr;
} }
return np; return np.release();
} }