From 560efb2c9ebc5a4ed0405bd64f61d2e958ed66c0 Mon Sep 17 00:00:00 2001 From: HungMingWu Date: Sun, 15 May 2022 06:15:38 +0800 Subject: [PATCH] Internals: Fix memory leak in V3FileLine (#3407) (#3408). No functional change intended. --- src/V3FileLine.cpp | 2 +- src/V3FileLine.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/V3FileLine.cpp b/src/V3FileLine.cpp index fa5e324fe..90e3c85e7 100644 --- a/src/V3FileLine.cpp +++ b/src/V3FileLine.cpp @@ -155,7 +155,7 @@ FileLine::FileLine(FileLine::EmptySecret) { } void FileLine::newContent() { - m_contentp = new VFileContent; + m_contentp = std::make_shared(); m_contentLineno = 1; } diff --git a/src/V3FileLine.h b/src/V3FileLine.h index 1928e8f5a..1ff0c06a4 100644 --- a/src/V3FileLine.h +++ b/src/V3FileLine.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -97,7 +98,7 @@ class FileLine final { int m_lastColumn = 0; // `line corrected token's last column number int m_filenameno; // `line corrected filename number int m_contentLineno = 0; // Line number within source stream - VFileContent* m_contentp = nullptr; // Source text contents line is within + std::shared_ptr m_contentp = nullptr; // Source text contents line is within FileLine* m_parent = nullptr; // Parent line that included this line std::bitset m_warnOn; bool m_waive = false; // Waive warning @@ -180,7 +181,7 @@ public: int firstColumn() const { return m_firstColumn; } int lastLineno() const { return m_lastLineno; } int lastColumn() const { return m_lastColumn; } - VFileContent* contentp() const { return m_contentp; } + std::shared_ptr contentp() const { return m_contentp; } // If not otherwise more specific, use last lineno for errors etc, // as the parser errors etc generally make more sense pointing at the last parse point int lineno() const { return m_lastLineno; }