Browse Source

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 15 years ago
parent
commit
1aba213a91
1 changed files with 16 additions and 15 deletions
  1. 16
    15
      SNFMulti.cpp

+ 16
- 15
SNFMulti.cpp View File



//// Version Info //// 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 //// Script Caller Methods




TokenMatrix* TryThis = NULL; // We need our candidate to remain in scope. 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 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 catch (TokenMatrix::BadFile) { // BadFile translates to FileError
RefreshInProgress = false;
throw FileError("_snf_LoadNewRulebase() TokenMatrix::BadFile"); throw FileError("_snf_LoadNewRulebase() TokenMatrix::BadFile");
} }
catch (TokenMatrix::BadMatrix) { // BadMatrix translates to AuthenticationError catch (TokenMatrix::BadMatrix) { // BadMatrix translates to AuthenticationError
RefreshInProgress = false;
throw AuthenticationError("_snf_LoadNewRulebase() TokenMatrix::BadMatrix"); throw AuthenticationError("_snf_LoadNewRulebase() TokenMatrix::BadMatrix");
} }
catch (TokenMatrix::BadAllocation) { // BadAllocation translates to AllocationError catch (TokenMatrix::BadAllocation) { // BadAllocation translates to AllocationError
RefreshInProgress = false;
throw AllocationError("_snf_LoadNewRulebase() TokenMatrix::BadAllocation"); throw AllocationError("_snf_LoadNewRulebase() TokenMatrix::BadAllocation");
} }
catch (TokenMatrix::OutOfRange) { // OutOfRange should never happen so PANIC! catch (TokenMatrix::OutOfRange) { // OutOfRange should never happen so PANIC!
RefreshInProgress = false;
throw Panic("_snf_LoadNewRulebase() TokenMatrix::OutOfRange"); throw Panic("_snf_LoadNewRulebase() TokenMatrix::OutOfRange");
} }
catch (exception e) { catch (exception e) {
RefreshInProgress = false;
throw; throw;
} }
catch (...) { // Something unpredicted happens? PANIC! catch (...) { // Something unpredicted happens? PANIC!
RefreshInProgress = false;
throw Panic("_snf_LoadNewRulebase() TokenMatrix.load() ???"); throw Panic("_snf_LoadNewRulebase() TokenMatrix.load() ???");
} }



Loading…
Cancel
Save