Use unique pointer to fix possible leak (#6104)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user