Skip to content

Commit 4ee7b9d

Browse files
authored
Use unique pointer to fix possible leak (assimp#6104)
1 parent e68ea14 commit 4ee7b9d

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

code/AssetLib/MD3/MD3Loader.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
55
66
Copyright (c) 2006-2025, assimp team
77
8-
9-
108
All rights reserved.
119
1210
Redistribution and use of this software in source and binary forms,

code/AssetLib/Obj/ObjFileParser.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -660,13 +660,13 @@ void ObjFileParser::getMaterialLib() {
660660
} else {
661661
absName = strMatName;
662662
}
663-
664-
IOStream *pFile = m_pIO->Open(absName);
663+
664+
std::unique_ptr<IOStream> pFile(m_pIO->Open(absName));
665665
if (nullptr == pFile) {
666666
ASSIMP_LOG_ERROR("OBJ: Unable to locate material file ", strMatName);
667667
std::string strMatFallbackName = m_originalObjFileName.substr(0, m_originalObjFileName.length() - 3) + "mtl";
668668
ASSIMP_LOG_INFO("OBJ: Opening fallback material file ", strMatFallbackName);
669-
pFile = m_pIO->Open(strMatFallbackName);
669+
pFile.reset(m_pIO->Open(strMatFallbackName));
670670
if (!pFile) {
671671
ASSIMP_LOG_ERROR("OBJ: Unable to locate fallback material file ", strMatFallbackName);
672672
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
@@ -679,8 +679,8 @@ void ObjFileParser::getMaterialLib() {
679679
// material files if the model doesn't use any materials, so we
680680
// allow that.
681681
std::vector<char> buffer;
682-
BaseImporter::TextFileToBuffer(pFile, buffer, BaseImporter::ALLOW_EMPTY);
683-
m_pIO->Close(pFile);
682+
BaseImporter::TextFileToBuffer(pFile.get(), buffer, BaseImporter::ALLOW_EMPTY);
683+
//m_pIO->Close(pFile);
684684

685685
// Importing the material library
686686
ObjFileMtlImporter mtlImporter(buffer, strMatName, m_pModel.get());

code/AssetLib/Obj/ObjFileParser.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ class ASSIMP_API ObjFileParser {
9090
void parseFile(IOStreamBuffer<char> &streamBuffer);
9191
/// Method to copy the new delimited word in the current line.
9292
void copyNextWord(char *pBuffer, size_t length);
93-
/// Method to copy the new line.
94-
// void copyNextLine(char *pBuffer, size_t length);
9593
/// Get the number of components in a line.
9694
size_t getNumComponentsInDataDefinition();
9795
/// Stores the vector
@@ -146,6 +144,7 @@ class ASSIMP_API ObjFileParser {
146144
unsigned int m_uiLine;
147145
//! Helper buffer
148146
char m_buffer[Buffersize];
147+
/// End of buffer
149148
const char *mEnd;
150149
/// Pointer to IO system instance.
151150
IOSystem *m_pIO;

0 commit comments

Comments
 (0)