diff options
author | Dan Liew <daniel.liew@imperial.ac.uk> | 2014-02-14 14:00:11 +0000 |
---|---|---|
committer | Dan Liew <daniel.liew@imperial.ac.uk> | 2014-02-14 14:00:11 +0000 |
commit | 3c49bee67765e3b58ff5cfd2dcc26568509e275b (patch) | |
tree | cbe3111891effdf3da687810afc31db27ba97447 | |
parent | 360f372b46478d4f94f8696f4931cd85c20beb88 (diff) | |
download | klee-3c49bee67765e3b58ff5cfd2dcc26568509e275b.tar.gz |
Refactor cleaning up memory in linkBCA() so that if linking fails
then clean up is performed.
-rw-r--r-- | lib/Module/ModuleUtil.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
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<std::string> &UndefinedSymbols) { } +/*! A helper function for linkBCA() which cleans up + * memory allocated by that function. + */ +static void CleanUpLinkBCA(std::vector<Module*> &archiveModules) +{ + for (std::vector<Module*>::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<Module*>::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; |