You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/04/27 07:42:57 UTC

[doris] 06/10: [bugfix](topn) fix memory leak in topn AcceptNullPredicate (#19060)

This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-2.0-alpha
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 1cd15a625c78082e8d6b22c778be91fdf4ed11ab
Author: Kang <kx...@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 | 20 +++++++++++++-------
 2 files changed, 18 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 b3cc66e67e..25f3fc10fb 100644
--- a/be/src/runtime/runtime_predicate.cpp
+++ b/be/src/runtime/runtime_predicate.cpp
@@ -17,6 +17,12 @@
 
 #include "runtime/runtime_predicate.h"
 
+#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"
 #include "olap/predicate_creator.h"
 
@@ -156,26 +162,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-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org