From 7d4cea92bc3f7d709f09c3f1ac77c5bbc71a6749 Mon Sep 17 00:00:00 2001 From: Nick Nobles Date: Wed, 15 May 2024 13:31:41 -0700 Subject: [PATCH] Fix singleton memory leaks Signed-off-by: Nick Nobles --- runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp | 2 +- .../org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp b/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp index c1e1499f85..40fb855b3b 100755 --- a/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp +++ b/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp @@ -14,7 +14,7 @@ ATNDeserializationOptions::ATNDeserializationOptions(ATNDeserializationOptions * _generateRuleBypassTransitions(options->_generateRuleBypassTransitions) {} const ATNDeserializationOptions& ATNDeserializationOptions::getDefaultOptions() { - static const ATNDeserializationOptions* const defaultOptions = new ATNDeserializationOptions(); + static const std::unique_ptr defaultOptions = std::make_unique(); return *defaultOptions; } diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg index 6fc4419d02..e557fc811d 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg @@ -147,7 +147,7 @@ struct StaticData final { #if ANTLR4_USE_THREAD_LOCAL_CACHE static thread_local #endif -StaticData *LexerStaticData = nullptr; +std::unique_ptr\<StaticData> LexerStaticData = nullptr; void LexerInitialize() { #if ANTLR4_USE_THREAD_LOCAL_CACHE @@ -175,7 +175,7 @@ void LexerInitialize() { } ); - LexerStaticData = staticData.release(); + LexerStaticData = std::move(staticData); } } @@ -380,7 +380,7 @@ struct StaticData final { #if ANTLR4_USE_THREAD_LOCAL_CACHE static thread_local #endif -StaticData *ParserStaticData = nullptr; +std::unique_ptr\<StaticData> ParserStaticData = nullptr; void ParserInitialize() { #if ANTLR4_USE_THREAD_LOCAL_CACHE @@ -402,7 +402,7 @@ void ParserInitialize() { } ); - ParserStaticData = staticData.release(); + ParserStaticData = std::move(staticData); } }