Destroy allocated resources on exception.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8969 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Misha Brukman 2003-10-08 19:55:47 +00:00
parent 608e75c604
commit 7f58de2b99

View File

@ -59,8 +59,13 @@ BytecodeFileReader::BytecodeFileReader(const std::string &Filename) {
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 @@ BytecodeBufferReader::BytecodeBufferReader(const unsigned char *Buf,
ParseBegin = Buffer = Buf;
MustDelete = false;
}
ParseBytecode(ParseBegin, Length, ModuleID);
try {
ParseBytecode(ParseBegin, Length, ModuleID);
} catch (...) {
if (MustDelete) delete [] Buffer;
throw;
}
}
BytecodeBufferReader::~BytecodeBufferReader() {