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

PVS V773
This commit is contained in:
Mark Roszko 2022-02-05 20:20:45 +00:00
parent 3af606a020
commit f5a56c1ebc
1 changed files with 3 additions and 6 deletions

View File

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