summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bytecode/Reader
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2004-11-16 06:41:05 +0000
committerReid Spencer <rspencer@reidspencer.com>2004-11-16 06:41:05 +0000
commit2df70a7e2f684384f750aa1ea68598c95cfb42bb (patch)
treebce2345fcc8361ca2a775e451f5e22bbb8e97236 /llvm/lib/Bytecode/Reader
parent2981914302875ed313ee80fbf0dc28adc6a2b983 (diff)
downloadbcm5719-llvm-2df70a7e2f684384f750aa1ea68598c95cfb42bb.tar.gz
bcm5719-llvm-2df70a7e2f684384f750aa1ea68598c95cfb42bb.zip
Per code review:\
* Get rid of memory leaks on exception \ * Provide better comments of how the memory handling works llvm-svn: 17876
Diffstat (limited to 'llvm/lib/Bytecode/Reader')
-rw-r--r--llvm/lib/Bytecode/Reader/ReaderWrappers.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/llvm/lib/Bytecode/Reader/ReaderWrappers.cpp b/llvm/lib/Bytecode/Reader/ReaderWrappers.cpp
index 7cdcf64de1e..c8958ad19c3 100644
--- a/llvm/lib/Bytecode/Reader/ReaderWrappers.cpp
+++ b/llvm/lib/Bytecode/Reader/ReaderWrappers.cpp
@@ -377,13 +377,12 @@ bool llvm::GetBytecodeSymbols(const sys::Path& fName,
std::auto_ptr<ModuleProvider> AMP( getBytecodeModuleProvider(fName.get()));
// Get the module from the provider
- Module* M = AMP->releaseModule();
+ Module* M = AMP->materializeModule();
// Get the symbols
getSymbols(M, symbols);
// Done with the module
- delete M;
return true;
} catch (...) {
@@ -393,12 +392,13 @@ bool llvm::GetBytecodeSymbols(const sys::Path& fName,
ModuleProvider*
llvm::GetBytecodeSymbols(const unsigned char*Buffer, unsigned Length,
- const std::string& ModuleID,
- std::vector<std::string>& symbols) {
+ const std::string& ModuleID,
+ std::vector<std::string>& symbols) {
+ ModuleProvider* MP = 0;
try {
- ModuleProvider* MP =
- getBytecodeBufferModuleProvider(Buffer, Length, ModuleID);
+ // Get the module provider
+ MP = getBytecodeBufferModuleProvider(Buffer, Length, ModuleID);
// Get the module from the provider
Module* M = MP->materializeModule();
@@ -406,11 +406,15 @@ llvm::GetBytecodeSymbols(const unsigned char*Buffer, unsigned Length,
// Get the symbols
getSymbols(M, symbols);
- // Done with the module
+ // Done with the module. Note that ModuleProvider will delete the
+ // Module when it is deleted. Also note that its the caller's responsibility
+ // to delete the ModuleProvider.
return MP;
} catch (...) {
- // Fall through
+ // We only delete the ModuleProvider here because its destructor will
+ // also delete the Module (we used materializeModule not releaseModule).
+ delete MP;
}
return 0;
}
OpenPOWER on IntegriCloud