From 3c49bee67765e3b58ff5cfd2dcc26568509e275b Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Fri, 14 Feb 2014 14:00:11 +0000 Subject: Refactor cleaning up memory in linkBCA() so that if linking fails then clean up is performed. --- lib/Module/ModuleUtil.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'lib/Module') diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp index 7a0e18d2..349defb3 100644 --- a/lib/Module/ModuleUtil.cpp +++ b/lib/Module/ModuleUtil.cpp @@ -152,6 +152,17 @@ GetAllUndefinedSymbols(Module *M, std::set &UndefinedSymbols) { } +/*! A helper function for linkBCA() which cleans up + * memory allocated by that function. + */ +static void CleanUpLinkBCA(std::vector &archiveModules) +{ + for (std::vector::iterator I = archiveModules.begin(), E = archiveModules.end(); + I != E; ++I) + { + delete (*I); + } +} /*! A helper function for klee::linkWithLibrary() that links in an archive of bitcode * modules into a composite bitcode module @@ -290,7 +301,7 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er // Linking failed SS << "Linking archive module with composite failed:" << errorMessage; SS.flush(); - delete M; + CleanUpLinkBCA(archiveModules); return false; } else @@ -320,13 +331,9 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er archiveModules.size() << " modules left.\n"); } while (undefinedSymbols != previouslyUndefinedSymbols); // Iterate until we reach a fixed point - // What's left in archiveModules we don't want to link in so free it - for (std::vector::iterator I = archiveModules.begin(), E = archiveModules.end(); - I != E; ++I) - { - delete (*I); - } + // What's left in archiveModules we don't want to link in so free it + CleanUpLinkBCA(archiveModules); return true; -- cgit 1.4.1