From 6359bd6fc5205b5c5ddabdea3085f088e50d5ce6 Mon Sep 17 00:00:00 2001 From: James Cherry Date: Sun, 7 Feb 2021 17:22:59 +0000 Subject: [PATCH] leaks --- liberty/LibertyParser.cc | 9 +++++++-- liberty/LibertyReader.cc | 15 ++++++++++++--- verilog/Verilog.i | 1 + verilog/VerilogReader.cc | 17 ++++++----------- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/liberty/LibertyParser.cc b/liberty/LibertyParser.cc index 715fcda8..c54535f7 100644 --- a/liberty/LibertyParser.cc +++ b/liberty/LibertyParser.cc @@ -522,8 +522,13 @@ libertyIncludeBegin(const char *filename) liberty_filename = filename; liberty_line = 1; } - else - libertyParseError("cannot open include file %s.", filename); + else { + // Copy the filename to the stack so it is deleted when + // libertyParseError throws an error. + string filename1(filename); + stringDelete(filename); + libertyParseError("cannot open include file %s.", filename1.c_str()); + } return stream; } diff --git a/liberty/LibertyReader.cc b/liberty/LibertyReader.cc index 8489d654..42d94c04 100644 --- a/liberty/LibertyReader.cc +++ b/liberty/LibertyReader.cc @@ -600,6 +600,7 @@ LibertyReader::endLibraryAttrs(LibertyGroup *group) else libWarn(31, group, "default_wire_load %s not found.", default_wireload_); stringDelete(default_wireload_); + default_wireload_ = nullptr; } if (default_wireload_selection_) { @@ -611,6 +612,7 @@ LibertyReader::endLibraryAttrs(LibertyGroup *group) libWarn(32, group, "default_wire_selection %s not found.", default_wireload_selection_); stringDelete(default_wireload_selection_); + default_wireload_selection_ = nullptr; } if (default_operating_condition_) { @@ -622,6 +624,7 @@ LibertyReader::endLibraryAttrs(LibertyGroup *group) libWarn(60, group, "default_operating_condition %s not found.", default_operating_condition_); stringDelete(default_operating_condition_); + default_operating_condition_ = nullptr; } bool missing_threshold = false; @@ -1074,8 +1077,10 @@ LibertyReader::visitDefaultWireLoad(LibertyAttr *attr) { if (library_) { const char *value = getAttrString(attr); - if (value) + if (value) { + stringDelete(default_wireload_); default_wireload_ = stringCopy(value); + } } } @@ -1100,8 +1105,10 @@ LibertyReader::visitDefaultWireLoadSelection(LibertyAttr *attr) { if (library_) { const char *value = getAttrString(attr); - if (value) + if (value) { + stringDelete(default_wireload_selection_); default_wireload_selection_ = stringCopy(value); + } } } @@ -1110,8 +1117,10 @@ LibertyReader::visitDefaultOperatingConditions(LibertyAttr *attr) { if (library_) { const char *value = getAttrString(attr); - if (value) + if (value) { + stringDelete(default_operating_condition_); default_operating_condition_ = stringCopy(value); + } } } diff --git a/verilog/Verilog.i b/verilog/Verilog.i index 40802cec..8847a896 100644 --- a/verilog/Verilog.i +++ b/verilog/Verilog.i @@ -60,6 +60,7 @@ write_verilog_cmd(const char *filename, Sta *sta = Sta::sta(); Network *network = sta->network(); writeVerilog(filename, sort, include_pwr_gnd, remove_cells, network); + delete remove_cells; } %} // inline diff --git a/verilog/VerilogReader.cc b/verilog/VerilogReader.cc index d4823dd3..1a70fba4 100644 --- a/verilog/VerilogReader.cc +++ b/verilog/VerilogReader.cc @@ -80,7 +80,10 @@ public: const char *msg, bool warn); ~VerilogError(); - void report(Report *report); + const char *msg() const { return msg_; } + const char *filename() const { return filename_; } + int id() const { return id_; } + int line() const { return line_; } bool warn() const { return warn_; } private: @@ -114,15 +117,6 @@ VerilogError::~VerilogError() stringDelete(msg_); } -void -VerilogError::report(Report *report) -{ - if (warn_) - report->fileWarn(id_, filename_, line_, "%s", msg_); - else - report->fileError(id_, filename_, line_, "%s", msg_); -} - class VerilogErrorCmp { public: @@ -2224,7 +2218,8 @@ VerilogReader::reportLinkErrors(Report *report) VerilogErrorSeq::Iterator error_iter(link_errors_); while (error_iter.hasNext()) { VerilogError *error = error_iter.next(); - error->report(report); + // Report as warnings to avoid throwing. + report->fileWarn(error->id(), error->filename(), error->line(), "%s", error->msg()); errors |= !error->warn(); delete error; }