From ef5e6a39dc41c8ab35121ed02b4c84ecfed504c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 7 Jan 2018 18:43:59 -0300 Subject: [PATCH] Fixed critical bug in IniFile. --HG-- branch : dev-2.1 --- include/eepp/system/inifile.hpp | 2 ++ src/eepp/system/inifile.cpp | 20 +++----------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/include/eepp/system/inifile.hpp b/include/eepp/system/inifile.hpp index 3d9e9f771..c02ae2276 100755 --- a/include/eepp/system/inifile.hpp +++ b/include/eepp/system/inifile.hpp @@ -218,6 +218,8 @@ class EE_API IniFile { /** Delete all comments for a key. */ bool deleteKeyComments ( unsigned const keyID ); bool deleteKeyComments ( std::string const keyname ); + + bool iniParsed() { return mIniReaded; } private: bool mCaseInsensitive; bool mIniReaded; diff --git a/src/eepp/system/inifile.cpp b/src/eepp/system/inifile.cpp index 6778c56c5..ac1b9a93e 100755 --- a/src/eepp/system/inifile.cpp +++ b/src/eepp/system/inifile.cpp @@ -60,11 +60,10 @@ bool IniFile::loadFromMemory( const Uint8* RAWData, const Uint32& size ) { std::string myfile; myfile.assign( reinterpret_cast (RAWData), size ); + clear(); mLines.clear(); mLines = String::split( myfile ); - mIniReaded = false; - return true; } @@ -81,11 +80,10 @@ bool IniFile::loadFromFile( const std::string& iniPath ) { f.read( (char*)&myfile[0], f.getSize() ); + clear(); mLines.clear(); mLines = String::split( myfile ); - mIniReaded = false; - return true; } else if ( PackManager::instance()->isFallbackToPacksActive() ) { std::string tPath( iniPath ); @@ -421,13 +419,6 @@ bool IniFile::deleteKey ( std::string const keyname ) { if ( keyID == noID ) return false; - // Now hopefully this destroys the vector lists within mKeys. - // Looking at source, this should be the case using the destructor. - // If not, I may have to do it explicitly. Memory leak check should tell. - // memleak_test.cpp shows that the following not required. - //mKeys[keyID].names.clear(); - //mKeys[keyID].values.clear(); - std::vector::iterator npos = mNames.begin() + keyID; std::vector::iterator kpos = mKeys.begin() + keyID; mNames.erase ( npos, npos + 1 ); @@ -437,12 +428,7 @@ bool IniFile::deleteKey ( std::string const keyname ) { } void IniFile::clear() { - // This loop not needed. The vector<> destructor seems to do - // all the work itself. memleak_test.cpp shows this. - //for ( unsigned i = 0; i < mKeys.size(); ++i) { - // mKeys[i].names.clear(); - // mKeys[i].values.clear(); - //} + mIniReaded = false; mNames.clear(); mKeys.clear(); mComments.clear();