Skip to content

Commit

Permalink
Merge pull request #1260 from williamfgc/kwsys_segfault
Browse files Browse the repository at this point in the history
Safe delete pointers in KWSys ClassFinalize
  • Loading branch information
williamfgc authored Mar 7, 2019
2 parents 425b6c5 + 0cc6c4c commit 20b0565
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions thirdparty/KWSys/adios2sys/SystemTools.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4666,15 +4666,28 @@ void SystemTools::ClassInitialize()
#endif
}

namespace {

template <class T>
void SafeDelete(T*& pointer)
{
if (pointer != nullptr) {
delete pointer;
pointer = nullptr;
}
}

} // end empty namespace

void SystemTools::ClassFinalize()
{
delete SystemTools::TranslationMap;
SafeDelete(SystemTools::TranslationMap);
#ifdef _WIN32
delete SystemTools::PathCaseMap;
delete SystemTools::EnvMap;
SafeDelete(SystemTools::PathCaseMap);
SafeDelete(SystemTools::EnvMap);
#endif
#ifdef __CYGWIN__
delete SystemTools::Cyg2Win32Map;
SafeDelete(SystemTools::Cyg2Win32Map);
#endif
}

Expand Down

0 comments on commit 20b0565

Please sign in to comment.