Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4309: memory leaks in C++ runtime #4374

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ ATNDeserializationOptions::ATNDeserializationOptions(ATNDeserializationOptions *
: _readOnly(false), _verifyATN(options->_verifyATN),
_generateRuleBypassTransitions(options->_generateRuleBypassTransitions) {}

const ATNDeserializationOptions& ATNDeserializationOptions::getDefaultOptions() {
static const ATNDeserializationOptions* const defaultOptions = new ATNDeserializationOptions();
return *defaultOptions;
ATNDeserializationOptions ATNDeserializationOptions::getDefaultOptions() {
return ATNDeserializationOptions();
}

void ATNDeserializationOptions::makeReadOnly() {
Expand Down
2 changes: 1 addition & 1 deletion runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ANTLR4CPP_PUBLIC ATNDeserializationOptions final {

ATNDeserializationOptions& operator=(const ATNDeserializationOptions&) = default;

static const ATNDeserializationOptions& getDefaultOptions();
static ATNDeserializationOptions getDefaultOptions();

bool isReadOnly() const { return _readOnly; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ struct <lexer.name; format = "cap">StaticData final {
#if ANTLR4_USE_THREAD_LOCAL_CACHE
static thread_local
#endif
<lexer.name; format = "cap">StaticData *<lexer.grammarName; format = "lower">LexerStaticData = nullptr;
std::unique_ptr\<<lexer.name; format = "cap">StaticData> <lexer.grammarName; format = "lower">LexerStaticData;

void <lexer.grammarName; format = "lower">LexerInitialize() {
#if ANTLR4_USE_THREAD_LOCAL_CACHE
Expand Down Expand Up @@ -175,7 +175,7 @@ void <lexer.grammarName; format = "lower">LexerInitialize() {
}
);
<atn>
<lexer.grammarName; format = "lower">LexerStaticData = staticData.release();
<lexer.grammarName; format = "lower">LexerStaticData = std::move(staticData);
}

}
Expand Down Expand Up @@ -380,7 +380,7 @@ struct <parser.name; format = "cap">StaticData final {
#if ANTLR4_USE_THREAD_LOCAL_CACHE
static thread_local
#endif
<parser.name; format = "cap">StaticData *<parser.grammarName; format = "lower">ParserStaticData = nullptr;
std::unique_ptr\<<parser.name; format = "cap">StaticData> <parser.grammarName; format = "lower">ParserStaticData;

void <parser.grammarName; format = "lower">ParserInitialize() {
#if ANTLR4_USE_THREAD_LOCAL_CACHE
Expand All @@ -402,7 +402,7 @@ void <parser.grammarName; format = "lower">ParserInitialize() {
}
);
<atn>
<parser.grammarName; format = "lower">ParserStaticData = staticData.release();
<parser.grammarName; format = "lower">ParserStaticData = std::move(staticData);
}

}
Expand Down
Loading