From 31623277e9ee6efe6be934c59037c8dc32818636 Mon Sep 17 00:00:00 2001 From: nebula-bots <88429921+nebula-bots@users.noreply.github.com> Date: Wed, 5 Jan 2022 15:17:53 +0800 Subject: [PATCH] fix parser memeory leak (#431) Co-authored-by: jie.wang <38901892+jievince@users.noreply.github.com> --- src/kvstore/raftex/Host.cpp | 7 ++----- src/kvstore/raftex/Host.h | 7 ++----- src/parser/parser.yy | 3 +++ src/parser/test/ParserTest.cpp | 15 +++++++++++++++ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/kvstore/raftex/Host.cpp b/src/kvstore/raftex/Host.cpp index 17dbe1e7c1d..faf610aa922 100644 --- a/src/kvstore/raftex/Host.cpp +++ b/src/kvstore/raftex/Host.cpp @@ -375,11 +375,8 @@ folly::Future Host::sendAppendLogRequest( return client->future_appendLog(*req); } -folly::Future Host::sendHeartbeat(folly::EventBase* eb, - TermID term, - LogID commitLogId, - TermID lastLogTerm, - LogID lastLogId) { +folly::Future Host::sendHeartbeat( + folly::EventBase* eb, TermID term, LogID commitLogId, TermID lastLogTerm, LogID lastLogId) { auto req = std::make_shared(); req->space_ref() = part_->spaceId(); req->part_ref() = part_->partitionId(); diff --git a/src/kvstore/raftex/Host.h b/src/kvstore/raftex/Host.h index c0d8b6633f1..8e1c3c14609 100644 --- a/src/kvstore/raftex/Host.h +++ b/src/kvstore/raftex/Host.h @@ -89,11 +89,8 @@ class Host final : public std::enable_shared_from_this { TermID lastLogTermSent, // The last log term being sent LogID lastLogIdSent); // The last log id being sent - folly::Future sendHeartbeat(folly::EventBase* eb, - TermID term, - LogID commitLogId, - TermID lastLogTerm, - LogID lastLogId); + folly::Future sendHeartbeat( + folly::EventBase* eb, TermID term, LogID commitLogId, TermID lastLogTerm, LogID lastLogId); const HostAddr& address() const { return addr_; diff --git a/src/parser/parser.yy b/src/parser/parser.yy index f5942b329ad..d777a45ea14 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -2634,6 +2634,7 @@ index_field } | name_label L_PAREN INTEGER R_PAREN { if ($3 > std::numeric_limits::max()) { + delete $1; throw nebula::GraphParser::syntax_error(@3, "Out of range:"); } $$ = new meta::cpp2::IndexFieldDef(); @@ -2942,6 +2943,8 @@ match_sentences assignment_sentence : VARIABLE ASSIGN set_sentence { if (qctx->existParameter(*$1)) { + delete $1; + delete $3; throw nebula::GraphParser::syntax_error(@1, "Variable definition conflicts with a parameter"); } else { $$ = new AssignmentSentence($1, $3); diff --git a/src/parser/test/ParserTest.cpp b/src/parser/test/ParserTest.cpp index 76e82948b33..80638557ab4 100644 --- a/src/parser/test/ParserTest.cpp +++ b/src/parser/test/ParserTest.cpp @@ -3376,6 +3376,21 @@ TEST_F(ParserTest, DetectMemoryLeakTest) { ASSERT_EQ(result.value()->toString(), "YIELD reduce(totalNum = 10, n IN range(1,3) | (totalNum+n))"); } + { + std::string query = "CREATE TAG INDEX IF NOT EXISTS std_index ON t1(c1(4294967296), c2)"; + auto result = parse(query); + ASSERT_FALSE(result.ok()) << result.status(); + ASSERT_EQ(result.status().toString(), "SyntaxError: Out of range: near `4294967296'"); + } + { + std::string query = "$param = GO FROM 'Tony Parker' over like YIELD like._dst AS vv"; + auto* ectx = qctx_->ectx(); + ectx->setValue("param", "TestData"); + auto result = parse(query); + ASSERT_FALSE(result.ok()) << result.status(); + ASSERT_EQ(result.status().toString(), + "SyntaxError: Variable definition conflicts with a parameter near `$param'"); + } } TEST_F(ParserTest, TestNameLabel) {