diff --git a/src/V3Global.cpp b/src/V3Global.cpp index 2b8a627fe..bfdfc1311 100644 --- a/src/V3Global.cpp +++ b/src/V3Global.cpp @@ -35,6 +35,12 @@ AstNetlist* V3Global::makeNetlist() { return newp; } +void V3Global::clear() { +#ifdef VL_LEAK_CHECK + if (m_rootp) VL_DO_CLEAR(m_rootp->deleteTree(), m_rootp = nullptr); +#endif +} + void V3Global::shutdown() { VL_DO_CLEAR(delete m_hierPlanp, m_hierPlanp = nullptr); // delete nullptr is safe } diff --git a/src/V3Global.h b/src/V3Global.h index 3c607052e..ec4b6d0f1 100644 --- a/src/V3Global.h +++ b/src/V3Global.h @@ -119,6 +119,7 @@ public: UASSERT(!m_rootp, "call once"); m_rootp = makeNetlist(); } + void clear(); void shutdown(); // Release allocated resorces // ACCESSORS (general) AstNetlist* rootp() const { return m_rootp; } diff --git a/src/Verilator.cpp b/src/Verilator.cpp index 147199e81..39d51bb70 100644 --- a/src/Verilator.cpp +++ b/src/Verilator.cpp @@ -623,10 +623,8 @@ static void verilate(const string& argString) { // Final writing shouldn't throw warnings, but... V3Error::abortIfWarnings(); -#ifdef VL_LEAK_CHECKS // Cleanup memory for valgrind leak analysis v3Global.clear(); -#endif FileLine::deleteAllRemaining(); }