From 4ee7b9d98dd1807f5c93f346c8f7fd73e1ffa441 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 15 Apr 2025 21:51:05 +0200 Subject: [PATCH] Use unique pointer to fix possible leak (#6104) --- code/AssetLib/MD3/MD3Loader.cpp | 2 -- code/AssetLib/Obj/ObjFileParser.cpp | 10 +++++----- code/AssetLib/Obj/ObjFileParser.h | 3 +-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/code/AssetLib/MD3/MD3Loader.cpp b/code/AssetLib/MD3/MD3Loader.cpp index 53444d7bb..0a5fc933c 100644 --- a/code/AssetLib/MD3/MD3Loader.cpp +++ b/code/AssetLib/MD3/MD3Loader.cpp @@ -5,8 +5,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2025, assimp team - - All rights reserved. Redistribution and use of this software in source and binary forms, diff --git a/code/AssetLib/Obj/ObjFileParser.cpp b/code/AssetLib/Obj/ObjFileParser.cpp index b8a15ab1e..f1f0b4017 100644 --- a/code/AssetLib/Obj/ObjFileParser.cpp +++ b/code/AssetLib/Obj/ObjFileParser.cpp @@ -660,13 +660,13 @@ void ObjFileParser::getMaterialLib() { } else { absName = strMatName; } - - IOStream *pFile = m_pIO->Open(absName); + + std::unique_ptr pFile(m_pIO->Open(absName)); if (nullptr == pFile) { ASSIMP_LOG_ERROR("OBJ: Unable to locate material file ", strMatName); std::string strMatFallbackName = m_originalObjFileName.substr(0, m_originalObjFileName.length() - 3) + "mtl"; ASSIMP_LOG_INFO("OBJ: Opening fallback material file ", strMatFallbackName); - pFile = m_pIO->Open(strMatFallbackName); + pFile.reset(m_pIO->Open(strMatFallbackName)); if (!pFile) { ASSIMP_LOG_ERROR("OBJ: Unable to locate fallback material file ", strMatFallbackName); m_DataIt = skipLine(m_DataIt, m_DataItEnd, m_uiLine); @@ -679,8 +679,8 @@ void ObjFileParser::getMaterialLib() { // material files if the model doesn't use any materials, so we // allow that. std::vector buffer; - BaseImporter::TextFileToBuffer(pFile, buffer, BaseImporter::ALLOW_EMPTY); - m_pIO->Close(pFile); + BaseImporter::TextFileToBuffer(pFile.get(), buffer, BaseImporter::ALLOW_EMPTY); + //m_pIO->Close(pFile); // Importing the material library ObjFileMtlImporter mtlImporter(buffer, strMatName, m_pModel.get()); diff --git a/code/AssetLib/Obj/ObjFileParser.h b/code/AssetLib/Obj/ObjFileParser.h index 93f2b78e9..7a0779bf2 100644 --- a/code/AssetLib/Obj/ObjFileParser.h +++ b/code/AssetLib/Obj/ObjFileParser.h @@ -90,8 +90,6 @@ protected: void parseFile(IOStreamBuffer &streamBuffer); /// Method to copy the new delimited word in the current line. void copyNextWord(char *pBuffer, size_t length); - /// Method to copy the new line. - // void copyNextLine(char *pBuffer, size_t length); /// Get the number of components in a line. size_t getNumComponentsInDataDefinition(); /// Stores the vector @@ -146,6 +144,7 @@ private: unsigned int m_uiLine; //! Helper buffer char m_buffer[Buffersize]; + /// End of buffer const char *mEnd; /// Pointer to IO system instance. IOSystem *m_pIO;