From a00c4d9a69bd90f3444d77b2196669cbdaf75b9e Mon Sep 17 00:00:00 2001 From: Horst Schirmeier Date: Fri, 9 Jan 2015 17:09:18 +0100 Subject: [PATCH] util/DwarfReader: plug file-descriptor leaks This change fixes several file-descriptor leaks in the DwarfReader implementation. The patch is taken from Richard Hellwig's not yet merged change I161f626d12ca7f2b7b9d13ba9cbc254eb55692f1. I did not apply any white-space cleanups to prevent conflicts when Richard's change will be merged later. Change-Id: Icd9c1bdeeab39e77900e2ce88b756a8cf7ade96a --- src/core/util/DwarfReader.cc | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/core/util/DwarfReader.cc b/src/core/util/DwarfReader.cc index 585fe588..0a56e4ff 100644 --- a/src/core/util/DwarfReader.cc +++ b/src/core/util/DwarfReader.cc @@ -130,8 +130,10 @@ bool DwarfReader::read_source_files(const std::string& fileName,std::list(addr) << " line source:" << normalize(lineSource) << endl; @@ -173,8 +183,10 @@ bool DwarfReader::read_source_files(const std::string& fileName,std::list Dwarf_Die die; // XXX: "if there are no sibling headers, die" | semantics unclear! if (dwarf_siblingof(dbg,0,&die,0)!=DW_DLV_OK) { + close(fd); return false; } @@ -219,6 +232,7 @@ bool DwarfReader::read_mapping(std::string fileName, std::list Dwarf_Line* lineBuffer; Dwarf_Signed lineCount; if (dwarf_srclines(die,&lineBuffer,&lineCount,0)!=DW_DLV_OK) { + close(fd); continue; //return false; } @@ -226,18 +240,22 @@ bool DwarfReader::read_mapping(std::string fileName, std::list for (int index=0;index // Shut down libdwarf if (dwarf_finish(dbg,0)!=DW_DLV_OK) { + close(fd); return false; }