From 36a5580f566e22e1a21243481baf762ffec18ff1 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Sat, 5 Feb 2022 14:37:51 -0500 Subject: [PATCH] Use unique_ptr to avoid memory leak in 3d model cache loading PVS V773 --- 3d-viewer/3d_cache/sg/ifsg_api.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/3d-viewer/3d_cache/sg/ifsg_api.cpp b/3d-viewer/3d_cache/sg/ifsg_api.cpp index bae4fe2478..617a2f65ba 100644 --- a/3d-viewer/3d_cache/sg/ifsg_api.cpp +++ b/3d-viewer/3d_cache/sg/ifsg_api.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include "plugins/3dapi/ifsg_api.h" @@ -232,14 +233,12 @@ SGNODE* S3D::ReadCache( const char* aFileName, void* aPluginMgr, return nullptr; } - SGNODE* np = new SCENEGRAPH( nullptr ); + std::unique_ptr np = std::make_unique( nullptr ); OPEN_ISTREAM( file, aFileName ); if( file.fail() ) { - delete np; - wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] failed to open file '%s'", __FILE__, __FUNCTION__, __LINE__, aFileName ); @@ -321,15 +320,13 @@ SGNODE* S3D::ReadCache( const char* aFileName, void* aPluginMgr, if( !rval ) { - delete np; - wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] problems encountered reading cache file '%s'", __FILE__, __FUNCTION__, __LINE__, aFileName ); return nullptr; } - return np; + return np.release(); }