diff --git a/src/OpenRoad.cc b/src/OpenRoad.cc index c8a8cf64aa..19b70ac0dd 100644 --- a/src/OpenRoad.cc +++ b/src/OpenRoad.cc @@ -78,6 +78,7 @@ #include "rmp/Restructure.h" #include "rsz/MakeResizer.hh" #include "rsz/Resizer.hh" +#include "sta/Sta.hh" #include "sta/VerilogReader.hh" #include "sta/VerilogWriter.hh" #include "stt/MakeSteinerTreeBuilder.h" @@ -120,9 +121,6 @@ OpenRoad::OpenRoad() OpenRoad::~OpenRoad() { delete verilog_network_; - // Temporarily removed until a crash can be resolved - // deleteDbSta(sta_); - // sta::deleteAllMemory(); delete ioPlacer_; delete resizer_; delete opendp_; @@ -140,7 +138,6 @@ OpenRoad::~OpenRoad() delete finale_; delete ram_gen_; delete antenna_checker_; - odb::dbDatabase::destroy(db_); delete partitionMgr_; delete pdngen_; delete icewall_; @@ -148,6 +145,19 @@ OpenRoad::~OpenRoad() delete stt_builder_; delete dft_; delete estimate_parasitics_; + // If the Python API creates and destructs multiple instances, + // not deleting the sta memory results in memory leaks. We also + // need to reinit the sta memory after deletion to make sure + // sta works for future instances as well. + sta::Sta* temp = nullptr; + if (sta_ != sta::Sta::sta()) { + temp = sta::Sta::sta(); + } + sta::Sta::setSta(sta_); + sta::deleteAllMemory(); + sta::initSta(); + sta::Sta::setSta(temp); + odb::dbDatabase::destroy(db_); delete logger_; delete verilog_reader_; delete callback_handler_;