This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 68d3111629 [bugfix](topn) fix memory leak in topn AcceptNullPredicate (#19060) 68d3111629 is described below commit 68d3111629778783f8facbd5f0ffd4724c7cd5a9 Author: Kang <kxiao.ti...@gmail.com> AuthorDate: Thu Apr 27 14:07:57 2023 +0800 [bugfix](topn) fix memory leak in topn AcceptNullPredicate (#19060) fix the memory leak reported by ASAN as follows. --- be/src/olap/accept_null_predicate.h | 6 +++++- be/src/runtime/runtime_predicate.cpp | 16 +++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/be/src/olap/accept_null_predicate.h b/be/src/olap/accept_null_predicate.h index d07e1a1031..bfff2910ca 100644 --- a/be/src/olap/accept_null_predicate.h +++ b/be/src/olap/accept_null_predicate.h @@ -18,7 +18,9 @@ #pragma once #include <cstdint> +#include <memory> +#include "common/factory_creator.h" #include "olap/column_predicate.h" #include "olap/rowset/segment_v2/bloom_filter.h" #include "olap/rowset/segment_v2/inverted_index_reader.h" @@ -34,6 +36,8 @@ namespace doris { * At parent, it's used for topn runtime predicate. */ class AcceptNullPredicate : public ColumnPredicate { + ENABLE_FACTORY_CREATOR(AcceptNullPredicate); + public: AcceptNullPredicate(ColumnPredicate* nested) : ColumnPredicate(nested->column_id(), nested->opposite()), _nested {nested} {} @@ -201,7 +205,7 @@ private: return "passnull predicate for " + _nested->debug_string(); } - ColumnPredicate* _nested; + std::unique_ptr<ColumnPredicate> _nested; }; } //namespace doris diff --git a/be/src/runtime/runtime_predicate.cpp b/be/src/runtime/runtime_predicate.cpp index a96669812d..f053b842c7 100644 --- a/be/src/runtime/runtime_predicate.cpp +++ b/be/src/runtime/runtime_predicate.cpp @@ -19,6 +19,8 @@ #include <stdint.h> +#include <memory> + // IWYU pragma: no_include <opentelemetry/common/threadlocal.h> #include "common/compiler_util.h" // IWYU pragma: keep #include "olap/accept_null_predicate.h" @@ -161,26 +163,26 @@ Status RuntimePredicate::update(const Field& value, const String& col_name, bool const TabletColumn& column = _tablet_schema->column_by_uid(col_unique_id); uint32_t index = _tablet_schema->field_index(col_unique_id); auto val = _get_value_fn(_orderby_extrem); - ColumnPredicate* pred = nullptr; + std::unique_ptr<ColumnPredicate> pred {nullptr}; if (is_reverse) { // For DESC sort, create runtime predicate col_name >= min_top_value // since values that < min_top_value are less than any value in current topn values - pred = create_comparison_predicate<PredicateType::GE>(column, index, val, false, - _predicate_arena.get()); + pred.reset(create_comparison_predicate<PredicateType::GE>(column, index, val, false, + _predicate_arena.get())); } else { // For ASC sort, create runtime predicate col_name <= max_top_value // since values that > min_top_value are large than any value in current topn values - pred = create_comparison_predicate<PredicateType::LE>(column, index, val, false, - _predicate_arena.get()); + pred.reset(create_comparison_predicate<PredicateType::LE>(column, index, val, false, + _predicate_arena.get())); } // For NULLS FIRST, wrap a AcceptNullPredicate to return true for NULL // since ORDER BY ASC/DESC should get NULL first but pred returns NULL // and NULL in where predicate will be treated as FALSE if (_nulls_first) { - pred = new AcceptNullPredicate(pred); + pred = AcceptNullPredicate::create_unique(pred.release()); } - _predictate.reset(pred); + _predictate.reset(pred.release()); return Status::OK(); } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org