Explorar el Código

Fixed memory leak when failing to authenticate a rulebase file.

git-svn-id: https://svn.microneil.com/svn/SNFMulti/trunk@27 dc71a809-1921-45c4-985c-09c81d0142d9
wx
madscientist hace 15 años
padre
commit
1aba213a91
Se han modificado 1 ficheros con 16 adiciones y 15 borrados
  1. 16
    15
      SNFMulti.cpp

+ 16
- 15
SNFMulti.cpp Ver fichero

@@ -23,7 +23,7 @@ using namespace std;

//// Version Info

const char* SNF_ENGINE_VERSION = "SNFMulti Engine Version 3.0.10 Build: " __DATE__ " " __TIME__;
const char* SNF_ENGINE_VERSION = "SNFMulti Engine Version 3.0.11 Build: " __DATE__ " " __TIME__;

//// Script Caller Methods

@@ -374,38 +374,39 @@ void snf_RulebaseHandler::_snf_LoadNewRulebase(){

TokenMatrix* TryThis = NULL; // We need our candidate to remain in scope.

try {
TryThis = new TokenMatrix(); // Grab a new Token Matrix
TryThis->Load(RuleFilePath); // Load it from the provided file path
TryThis->Validate(SecurityKey); // Validate it with the provided security key
TryThis->Verify(SecurityKey); // Verify that it is not corrupt.
try { // This try block decodes the problem.
try { // This try block does cleanup work.
TryThis = new TokenMatrix(); // Grab a new Token Matrix
TryThis->Load(RuleFilePath); // Load it from the provided file path
TryThis->Validate(SecurityKey); // Validate it with the provided security key
TryThis->Verify(SecurityKey); // Verify that it is not corrupt.
}
catch(...) { // Clean up after any exceptions.
RefreshInProgress = false; // We're not refreshing now.
if(TryThis) { // If we allocated a TokenMatrix then
delete TryThis; // we need to reclaim the memory
TryThis = 0; // and erase the pointer.
} // With everything nice and clean we can
throw; // rethrow he exception for decoding.
}
} // If nothing threw, we're golden!

// If the rulebase is bad then throw the proper exception and
// end/unlock the refresh process.

catch (TokenMatrix::BadFile) { // BadFile translates to FileError
RefreshInProgress = false;
throw FileError("_snf_LoadNewRulebase() TokenMatrix::BadFile");
}
catch (TokenMatrix::BadMatrix) { // BadMatrix translates to AuthenticationError
RefreshInProgress = false;
throw AuthenticationError("_snf_LoadNewRulebase() TokenMatrix::BadMatrix");
}
catch (TokenMatrix::BadAllocation) { // BadAllocation translates to AllocationError
RefreshInProgress = false;
throw AllocationError("_snf_LoadNewRulebase() TokenMatrix::BadAllocation");
}
catch (TokenMatrix::OutOfRange) { // OutOfRange should never happen so PANIC!
RefreshInProgress = false;
throw Panic("_snf_LoadNewRulebase() TokenMatrix::OutOfRange");
}
catch (exception e) {
RefreshInProgress = false;
throw;
}
catch (...) { // Something unpredicted happens? PANIC!
RefreshInProgress = false;
throw Panic("_snf_LoadNewRulebase() TokenMatrix.load() ???");
}


Cargando…
Cancelar
Guardar