[llvm-commits] CVS: llvm/lib/Bytecode/Reader/Reader.h ReaderWrappers.cpp
Chris Lattner
sabre at nondot.org
Thu Oct 12 11:32:45 PDT 2006
Changes in directory llvm/lib/Bytecode/Reader:
Reader.h updated: 1.33 -> 1.34
ReaderWrappers.cpp updated: 1.57 -> 1.58
---
Log message:
Fix massive resource leaks in the bytecode reader. Reading a bytecode file
with ParseBytecodeFile used to leak both a ModuleProvider (and related
bytecode parser stuff attached to it) AND a file descriptor, which was
never closed. This prevented gccld/llvm-ld/llvm-link from linking together
apps with more that ~252 .bc files on darwin.
---
Diffs of the changes: (+46 -45)
Reader.h | 12 ++++----
ReaderWrappers.cpp | 79 ++++++++++++++++++++++++++---------------------------
2 files changed, 46 insertions(+), 45 deletions(-)
Index: llvm/lib/Bytecode/Reader/Reader.h
diff -u llvm/lib/Bytecode/Reader/Reader.h:1.33 llvm/lib/Bytecode/Reader/Reader.h:1.34
--- llvm/lib/Bytecode/Reader/Reader.h:1.33 Fri Sep 1 15:35:17 2006
+++ llvm/lib/Bytecode/Reader/Reader.h Thu Oct 12 13:32:30 2006
@@ -248,6 +248,12 @@
/// @brief Parse a string constants block
void ParseStringConstants(unsigned NumEntries, ValueTable &Tab);
+ /// @brief Release our memory.
+ void freeState() {
+ freeTable(FunctionValues);
+ freeTable(ModuleValues);
+ }
+
/// @}
/// @name Data
/// @{
@@ -467,12 +473,6 @@
/// given constant.
void ResolveReferencesToConstant(Constant *C, unsigned Typ, unsigned Slot);
- /// @brief Release our memory.
- void freeState() {
- freeTable(FunctionValues);
- freeTable(ModuleValues);
- }
-
/// @brief Free a table, making sure to free the ValueList in the table.
void freeTable(ValueTable &Tab) {
while (!Tab.empty()) {
Index: llvm/lib/Bytecode/Reader/ReaderWrappers.cpp
diff -u llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.57 llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.58
--- llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.57 Fri Aug 25 12:43:11 2006
+++ llvm/lib/Bytecode/Reader/ReaderWrappers.cpp Thu Oct 12 13:32:30 2006
@@ -44,15 +44,17 @@
public:
BytecodeFileReader(const std::string &Filename, llvm::BytecodeHandler* H=0);
bool read(std::string* ErrMsg);
+
+ void freeState() {
+ BytecodeReader::freeState();
+ mapFile.close();
+ }
};
}
BytecodeFileReader::BytecodeFileReader(const std::string &Filename,
- llvm::BytecodeHandler* H )
- : BytecodeReader(H)
- , fileName(Filename)
- , mapFile()
-{
+ llvm::BytecodeHandler* H)
+ : BytecodeReader(H), fileName(Filename) {
}
bool BytecodeFileReader::read(std::string* ErrMsg) {
@@ -63,10 +65,7 @@
return true;
}
unsigned char* buffer = reinterpret_cast<unsigned char*>(mapFile.base());
- if (ParseBytecode(buffer, mapFile.size(), fileName, ErrMsg)) {
- return true;
- }
- return false;
+ return ParseBytecode(buffer, mapFile.size(), fileName, ErrMsg);
}
//===----------------------------------------------------------------------===//
@@ -101,14 +100,9 @@
BytecodeBufferReader::BytecodeBufferReader(const unsigned char *buf,
unsigned len,
const std::string &modID,
- llvm::BytecodeHandler* H)
- : BytecodeReader(H)
- , Buffer(0)
- , Buf(buf)
- , Length(len)
- , ModuleID(modID)
- , MustDelete(false)
-{
+ llvm::BytecodeHandler *H)
+ : BytecodeReader(H), Buffer(0), Buf(buf), Length(len), ModuleID(modID)
+ , MustDelete(false) {
}
BytecodeBufferReader::~BytecodeBufferReader() {
@@ -300,8 +294,8 @@
llvm::getBytecodeBufferModuleProvider(const unsigned char *Buffer,
unsigned Length,
const std::string &ModuleID,
- std::string* ErrMsg,
- BytecodeHandler* H) {
+ std::string *ErrMsg,
+ BytecodeHandler *H) {
BytecodeBufferReader* rdr =
new BytecodeBufferReader(Buffer, Length, ModuleID, H);
if (rdr->read(ErrMsg))
@@ -313,12 +307,13 @@
///
Module *llvm::ParseBytecodeBuffer(const unsigned char *Buffer, unsigned Length,
const std::string &ModuleID,
- std::string *ErrMsg){
- ModuleProvider* MP =
+ std::string *ErrMsg) {
+ ModuleProvider *MP =
getBytecodeBufferModuleProvider(Buffer, Length, ModuleID, ErrMsg, 0);
- if (!MP)
- return 0;
- return MP->releaseModule();
+ if (!MP) return 0;
+ Module *M = MP->releaseModule();
+ delete MP;
+ return M;
}
/// getBytecodeModuleProvider - lazy function-at-a-time loading from a file
@@ -347,9 +342,10 @@
Module *llvm::ParseBytecodeFile(const std::string &Filename,
std::string *ErrMsg) {
ModuleProvider* MP = getBytecodeModuleProvider(Filename, ErrMsg);
- if (!MP)
- return 0;
- return MP->releaseModule();
+ if (!MP) return 0;
+ Module *M = MP->releaseModule();
+ delete MP;
+ return M;
}
// AnalyzeBytecodeFile - analyze one file
@@ -358,13 +354,13 @@
BytecodeAnalysis& bca, ///< Statistical output
std::string *ErrMsg, ///< Error output
std::ostream* output ///< Dump output
-)
-{
+) {
BytecodeHandler* AH = createBytecodeAnalyzerHandler(bca,output);
ModuleProvider* MP = getBytecodeModuleProvider(Filename, ErrMsg, AH);
- if (!MP)
- return 0;
- return MP->releaseModule();
+ if (!MP) return 0;
+ Module *M = MP->releaseModule();
+ delete MP;
+ return M;
}
// AnalyzeBytecodeBuffer - analyze a buffer
@@ -380,15 +376,16 @@
BytecodeHandler* hdlr = createBytecodeAnalyzerHandler(bca, output);
ModuleProvider* MP =
getBytecodeBufferModuleProvider(Buffer, Length, ModuleID, ErrMsg, hdlr);
- if (!MP)
- return 0;
- return MP->releaseModule();
+ if (!MP) return 0;
+ Module *M = MP->releaseModule();
+ delete MP;
+ return M;
}
bool llvm::GetBytecodeDependentLibraries(const std::string &fname,
Module::LibraryListType& deplibs,
std::string* ErrMsg) {
- ModuleProvider* MP = getBytecodeModuleProvider(fname, ErrMsg);
+ ModuleProvider* MP = getBytecodeModuleProvider(fname, ErrMsg);
if (!MP) {
deplibs.clear();
return true;
@@ -396,6 +393,7 @@
Module* M = MP->releaseModule();
deplibs = M->getLibraries();
delete M;
+ delete MP;
return false;
}
@@ -417,19 +415,22 @@
bool llvm::GetBytecodeSymbols(const sys::Path& fName,
std::vector<std::string>& symbols,
std::string* ErrMsg) {
- ModuleProvider* MP = getBytecodeModuleProvider(fName.toString(), ErrMsg);
+ ModuleProvider *MP = getBytecodeModuleProvider(fName.toString(), ErrMsg);
if (!MP)
return true;
// Get the module from the provider
Module* M = MP->materializeModule();
- if (M == 0)
+ if (M == 0) {
+ delete MP;
return true;
+ }
// Get the symbols
getSymbols(M, symbols);
- // Done with the module
+ // Done with the module.
+ delete MP;
return true;
}
More information about the llvm-commits
mailing list