Destroy allocated resources on exception.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8969 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Bytecode/Reader/ReaderWrappers.cpp b/lib/Bytecode/Reader/ReaderWrappers.cpp
index 99c0e6b..9b63274 100644
--- a/lib/Bytecode/Reader/ReaderWrappers.cpp
+++ b/lib/Bytecode/Reader/ReaderWrappers.cpp
@@ -59,8 +59,13 @@
if (Buffer == (unsigned char*)MAP_FAILED)
throw std::string("Error mmapping file!");
- // Parse the bytecode we mmapped in
- ParseBytecode(Buffer, Length, Filename);
+ try {
+ // Parse the bytecode we mmapped in
+ ParseBytecode(Buffer, Length, Filename);
+ } catch (...) {
+ munmap((char*)Buffer, Length);
+ throw;
+ }
}
BytecodeFileReader::~BytecodeFileReader() {
@@ -106,7 +111,12 @@
ParseBegin = Buffer = Buf;
MustDelete = false;
}
- ParseBytecode(ParseBegin, Length, ModuleID);
+ try {
+ ParseBytecode(ParseBegin, Length, ModuleID);
+ } catch (...) {
+ if (MustDelete) delete [] Buffer;
+ throw;
+ }
}
BytecodeBufferReader::~BytecodeBufferReader() {