Просмотр исходного кода

Use unique pointer to fix possible leak

Kim Kulling 3 месяцев назад
Родитель
Сommit
c7872781c9
3 измененных файлов с 6 добавлено и 9 удалено
  1. 0 2
      code/AssetLib/MD3/MD3Loader.cpp
  2. 5 5
      code/AssetLib/Obj/ObjFileParser.cpp
  3. 1 2
      code/AssetLib/Obj/ObjFileParser.h

+ 0 - 2
code/AssetLib/MD3/MD3Loader.cpp

@@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
 
 
 Copyright (c) 2006-2025, assimp team
 Copyright (c) 2006-2025, assimp team
 
 
-
-
 All rights reserved.
 All rights reserved.
 
 
 Redistribution and use of this software in source and binary forms,
 Redistribution and use of this software in source and binary forms,

+ 5 - 5
code/AssetLib/Obj/ObjFileParser.cpp

@@ -660,13 +660,13 @@ void ObjFileParser::getMaterialLib() {
     } else {
     } else {
         absName = strMatName;
         absName = strMatName;
     }
     }
-
-    IOStream *pFile = m_pIO->Open(absName);
+	
+	std::unique_ptr<IOStream> pFile(m_pIO->Open(absName));
     if (nullptr == pFile) {
     if (nullptr == pFile) {
         ASSIMP_LOG_ERROR("OBJ: Unable to locate material file ", strMatName);
         ASSIMP_LOG_ERROR("OBJ: Unable to locate material file ", strMatName);
         std::string strMatFallbackName = m_originalObjFileName.substr(0, m_originalObjFileName.length() - 3) + "mtl";
         std::string strMatFallbackName = m_originalObjFileName.substr(0, m_originalObjFileName.length() - 3) + "mtl";
         ASSIMP_LOG_INFO("OBJ: Opening fallback material file ", strMatFallbackName);
         ASSIMP_LOG_INFO("OBJ: Opening fallback material file ", strMatFallbackName);
-        pFile = m_pIO->Open(strMatFallbackName);
+        pFile.reset(m_pIO->Open(strMatFallbackName));
         if (!pFile) {
         if (!pFile) {
             ASSIMP_LOG_ERROR("OBJ: Unable to locate fallback material file ", strMatFallbackName);
             ASSIMP_LOG_ERROR("OBJ: Unable to locate fallback material file ", strMatFallbackName);
             m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
             m_DataIt = skipLine<DataArrayIt>(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
     // material files if the model doesn't use any materials, so we
     // allow that.
     // allow that.
     std::vector<char> buffer;
     std::vector<char> 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
     // Importing the material library
     ObjFileMtlImporter mtlImporter(buffer, strMatName, m_pModel.get());
     ObjFileMtlImporter mtlImporter(buffer, strMatName, m_pModel.get());

+ 1 - 2
code/AssetLib/Obj/ObjFileParser.h

@@ -90,8 +90,6 @@ protected:
     void parseFile(IOStreamBuffer<char> &streamBuffer);
     void parseFile(IOStreamBuffer<char> &streamBuffer);
     /// Method to copy the new delimited word in the current line.
     /// Method to copy the new delimited word in the current line.
     void copyNextWord(char *pBuffer, size_t length);
     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.
     /// Get the number of components in a line.
     size_t getNumComponentsInDataDefinition();
     size_t getNumComponentsInDataDefinition();
     /// Stores the vector
     /// Stores the vector
@@ -146,6 +144,7 @@ private:
     unsigned int m_uiLine;
     unsigned int m_uiLine;
     //! Helper buffer
     //! Helper buffer
     char m_buffer[Buffersize];
     char m_buffer[Buffersize];
+	/// End of buffer
     const char *mEnd;
     const char *mEnd;
     /// Pointer to IO system instance.
     /// Pointer to IO system instance.
     IOSystem *m_pIO;
     IOSystem *m_pIO;