Use unique pointer to fix possible leak (#6104)

This commit is contained in:
Kim Kulling
2025-04-15 21:51:05 +02:00
committed by GitHub
parent e68ea14f56
commit 4ee7b9d98d
3 changed files with 6 additions and 9 deletions

View File

@@ -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,

View File

@@ -660,13 +660,13 @@ void ObjFileParser::getMaterialLib() {
} else {
absName = strMatName;
}
IOStream *pFile = m_pIO->Open(absName);
std::unique_ptr<IOStream> 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<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
// allow that.
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
ObjFileMtlImporter mtlImporter(buffer, strMatName, m_pModel.get());

View File

@@ -90,8 +90,6 @@ protected:
void parseFile(IOStreamBuffer<char> &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;