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 2020/04/22 14:59:55 UTC

[incubator-doris] branch master updated: [LSAN] Fix some memory leak detected by LSAN (#3326)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 4a7a88e  [LSAN] Fix some memory leak detected by LSAN (#3326)
4a7a88e is described below

commit 4a7a88ede13a22af4080248ce6470038e2b09b75
Author: Yingchun Lai <40...@qq.com>
AuthorDate: Wed Apr 22 22:59:44 2020 +0800

    [LSAN] Fix some memory leak detected by LSAN (#3326)
---
 be/src/exec/es/es_predicate.h                      |  1 +
 be/src/exec/es/es_query_builder.h                  |  6 +-
 be/src/http/http_request.cpp                       |  3 +-
 be/src/http/http_request.h                         |  6 +-
 be/src/olap/file_helper.cpp                        | 16 ++--
 be/src/olap/file_helper.h                          |  3 -
 be/src/olap/fs/fs_util.cpp                         |  3 +-
 be/src/olap/olap_common.h                          |  6 +-
 be/src/olap/olap_cond.h                            |  3 +
 be/src/olap/rowset/column_data.cpp                 |  2 +-
 be/src/olap/rowset/segment_v2/encoding_info.cpp    |  8 +-
 be/src/olap/rowset_graph.cpp                       | 36 ++++-----
 be/src/olap/storage_engine.cpp                     |  6 --
 be/src/plugin/plugin_loader.cpp                    |  2 +-
 be/src/plugin/plugin_loader.h                      |  6 +-
 be/src/plugin/plugin_mgr.cpp                       |  1 -
 be/src/runtime/runtime_state.cpp                   |  4 +
 be/src/runtime/thread_resource_mgr.cpp             |  9 +++
 be/src/runtime/thread_resource_mgr.h               |  1 +
 be/src/util/block_compression.cpp                  |  7 +-
 be/src/util/debug/leak_annotations.h               | 85 +++++++++++++++++++++
 .../debug/leakcheck_disabler.h}                    | 45 ++++++-----
 be/src/util/doris_metrics.cpp                      |  7 +-
 be/src/util/doris_metrics.h                        |  8 +-
 be/src/util/dynamic_util.cpp                       |  6 +-
 be/test/exec/es_predicate_test.cpp                 |  3 +
 be/test/exec/es_query_builder_test.cpp             | 21 ++++-
 be/test/exec/es_scan_node_test.cpp                 |  3 +-
 be/test/exec/plain_text_line_reader_bzip_test.cpp  |  6 ++
 be/test/exec/plain_text_line_reader_gzip_test.cpp  |  7 ++
 .../exec/plain_text_line_reader_lz4frame_test.cpp  |  6 ++
 be/test/exec/tablet_sink_test.cpp                  | 35 ++++++---
 be/test/exprs/percentile_approx_test.cpp           |  4 +
 be/test/exprs/string_functions_test.cpp            |  9 +++
 be/test/exprs/timestamp_functions_test.cpp         |  3 +
 be/test/http/stream_load_test.cpp                  |  9 +++
 be/test/olap/bloom_filter_test.cpp                 |  1 +
 be/test/olap/column_reader_test.cpp                | 33 +-------
 be/test/olap/comparison_predicate_test.cpp         | 15 ++++
 be/test/olap/delete_handler_test.cpp               |  2 +
 be/test/olap/in_list_predicate_test.cpp            |  9 +++
 be/test/olap/null_predicate_test.cpp               |  7 ++
 be/test/olap/olap_snapshot_converter_test.cpp      |  5 +-
 be/test/olap/rowset/alpha_rowset_test.cpp          |  4 -
 be/test/olap/rowset/beta_rowset_test.cpp           |  4 +
 be/test/olap/rowset/rowset_converter_test.cpp      |  9 ++-
 be/test/olap/rowset/rowset_meta_manager_test.cpp   |  4 +-
 .../olap/rowset/segment_v2/bitmap_index_test.cpp   |  4 +
 .../olap/rowset/segment_v2/zone_map_index_test.cpp |  3 +
 be/test/olap/run_length_byte_test.cpp              | 89 ++++++++++++++--------
 be/test/olap/schema_change_test.cpp                | 46 +++++++++--
 be/test/olap/storage_types_test.cpp                |  1 +
 be/test/olap/stream_index_test.cpp                 |  8 ++
 be/test/olap/tablet_mgr_test.cpp                   |  5 +-
 be/test/olap/txn_manager_test.cpp                  |  3 +
 be/test/plugin/plugin_mgr_test.cpp                 | 10 +--
 be/test/runtime/external_scan_context_mgr_test.cpp |  3 +
 be/test/runtime/memory_scratch_sink_test.cpp       | 30 +++++---
 be/test/util/arrow/arrow_work_flow_test.cpp        | 22 +++---
 59 files changed, 493 insertions(+), 210 deletions(-)

diff --git a/be/src/exec/es/es_predicate.h b/be/src/exec/es/es_predicate.h
index 3618873..5c0a72b 100644
--- a/be/src/exec/es/es_predicate.h
+++ b/be/src/exec/es/es_predicate.h
@@ -82,6 +82,7 @@ struct ExtColumnDesc {
 struct ExtPredicate {
     ExtPredicate(TExprNodeType::type node_type) : node_type(node_type) {
     }
+    virtual ~ExtPredicate() {}
 
     TExprNodeType::type node_type;
 };
diff --git a/be/src/exec/es/es_query_builder.h b/be/src/exec/es/es_query_builder.h
index 82d835a..2a9da61 100644
--- a/be/src/exec/es/es_query_builder.h
+++ b/be/src/exec/es/es_query_builder.h
@@ -27,11 +27,9 @@
 namespace doris {
 
 class QueryBuilder {
-
 public:
     virtual void to_json(rapidjson::Document* document, rapidjson::Value* query) = 0;
-    virtual ~QueryBuilder() {
-    };
+    virtual ~QueryBuilder() {}
 };
 
 // process esquery(fieldA, json dsl) function
@@ -117,7 +115,7 @@ class BooleanQueryBuilder : public QueryBuilder {
 public:
     BooleanQueryBuilder(const std::vector<ExtPredicate*>& predicates);
     BooleanQueryBuilder();
-    ~BooleanQueryBuilder();
+    virtual ~BooleanQueryBuilder();
     // class method for transfer predicate to es query value, invoker should enclose this value with `query`
     static void to_query(const std::vector<EsPredicate*>& predicates, rapidjson::Document* root, rapidjson::Value* query);
     // validate esquery syntax
diff --git a/be/src/http/http_request.cpp b/be/src/http/http_request.cpp
index cb2a31f..cdf1bb4 100644
--- a/be/src/http/http_request.cpp
+++ b/be/src/http/http_request.cpp
@@ -43,7 +43,8 @@ HttpRequest::HttpRequest(evhttp_request* evhttp_request)
 }
 
 HttpRequest::~HttpRequest() {
-    if (_handler != nullptr && _handler_ctx != nullptr) {
+    if (_handler_ctx != nullptr) {
+        DCHECK(_handler != nullptr);
         _handler->free_handler_ctx(_handler_ctx);
     }
 }
diff --git a/be/src/http/http_request.h b/be/src/http/http_request.h
index f464cb8..b5a83df 100644
--- a/be/src/http/http_request.h
+++ b/be/src/http/http_request.h
@@ -22,6 +22,7 @@
 #include <string>
 
 #include <boost/algorithm/string.hpp>
+#include <glog/logging.h>
 
 #include "http/http_common.h"
 #include "http/http_headers.h"
@@ -88,7 +89,10 @@ public:
     struct evhttp_request* get_evhttp_request() const { return _ev_req; }
 
     void* handler_ctx() const { return _handler_ctx; }
-    void set_handler_ctx(void* ctx) { _handler_ctx = ctx; }
+    void set_handler_ctx(void* ctx) {
+        DCHECK(_handler != nullptr);
+        _handler_ctx = ctx;
+    }
 
     const char* remote_host() const;
 
diff --git a/be/src/olap/file_helper.cpp b/be/src/olap/file_helper.cpp
index da7dc4d..cb574e6 100644
--- a/be/src/olap/file_helper.cpp
+++ b/be/src/olap/file_helper.cpp
@@ -25,6 +25,7 @@
 
 #include <errno.h>
 
+#include "common/config.h"
 #include "olap/olap_common.h"
 #include "olap/olap_define.h"
 #include "olap/utils.h"
@@ -34,7 +35,7 @@ using std::string;
 
 namespace doris {
 
-Cache* FileHandler::_s_fd_cache;
+Cache* FileHandler::_s_fd_cache = nullptr;
 
 FileHandler::FileHandler() :
         _fd(-1),
@@ -42,6 +43,10 @@ FileHandler::FileHandler() :
         _file_name(""),
         _is_using_cache(false),
         _cache_handle(NULL) {
+    static std::once_flag once_flag;
+    std::call_once(once_flag, [] {
+        _s_fd_cache = new_lru_cache(config::file_descriptor_cache_capacity);
+    });
 }
 
 FileHandler::~FileHandler() {
@@ -86,11 +91,10 @@ OLAPStatus FileHandler::open_with_cache(const string& file_name, int flag) {
     }
 
     CacheKey key(file_name.c_str(), file_name.size());
-    Cache* fd_cache = get_fd_cache();
-    _cache_handle = fd_cache->lookup(key);
+    _cache_handle = _s_fd_cache->lookup(key);
     if (NULL != _cache_handle) {
         FileDescriptor* file_desc =
-            reinterpret_cast<FileDescriptor*>(fd_cache->value(_cache_handle));
+            reinterpret_cast<FileDescriptor*>(_s_fd_cache->value(_cache_handle));
         _fd = file_desc->fd;
         VLOG(3) << "success to open file with cache. file_name=" << file_name
                 << ", mode=" << flag << " fd=" << _fd;
@@ -106,7 +110,7 @@ OLAPStatus FileHandler::open_with_cache(const string& file_name, int flag) {
             return OLAP_ERR_IO_ERROR;
         }
         FileDescriptor* file_desc = new FileDescriptor(_fd);
-        _cache_handle = fd_cache->insert(
+        _cache_handle = _s_fd_cache->insert(
                             key, file_desc, 1,
                             &_delete_cache_file_descriptor);
         VLOG(3) << "success to open file with cache. "
@@ -148,7 +152,7 @@ OLAPStatus FileHandler::open_with_mode(const string& file_name, int flag, int mo
 }
 
 OLAPStatus FileHandler::release() {
-    get_fd_cache()->release(_cache_handle);
+    _s_fd_cache->release(_cache_handle);
     _cache_handle = NULL;
     _is_using_cache = false;
     return OLAP_SUCCESS;
diff --git a/be/src/olap/file_helper.h b/be/src/olap/file_helper.h
index 9130f37..25c6217 100644
--- a/be/src/olap/file_helper.h
+++ b/be/src/olap/file_helper.h
@@ -104,9 +104,6 @@ public:
     static Cache* get_fd_cache() {
         return _s_fd_cache;
     }
-    static void set_fd_cache(Cache* cache) {
-        _s_fd_cache = cache;
-    }
 
 private:
     static Cache* _s_fd_cache;
diff --git a/be/src/olap/fs/fs_util.cpp b/be/src/olap/fs/fs_util.cpp
index b3d504b..a993e67 100644
--- a/be/src/olap/fs/fs_util.cpp
+++ b/be/src/olap/fs/fs_util.cpp
@@ -38,7 +38,8 @@ BlockManager* block_manager() {
 BlockManager* block_mgr_for_ut() {
     fs::BlockManagerOptions bm_opts;
     bm_opts.read_only = false;
-    return new FileBlockManager(Env::Default(), std::move(bm_opts));
+    static FileBlockManager block_mgr(Env::Default(), std::move(bm_opts));
+    return &block_mgr;
 }
 
 } // namespace fs_util
diff --git a/be/src/olap/olap_common.h b/be/src/olap/olap_common.h
index 311bd53..3a62b63 100644
--- a/be/src/olap/olap_common.h
+++ b/be/src/olap/olap_common.h
@@ -222,8 +222,10 @@ struct HashOfVersion {
 
 // It is used to represent Graph vertex.
 struct Vertex {
-    int64_t value;
-    std::list<int64_t>* edges;
+    int64_t value = 0;
+    std::list<int64_t> edges;
+
+    Vertex(int64_t v) : value(v) {}
 };
 
 class Field;
diff --git a/be/src/olap/olap_cond.h b/be/src/olap/olap_cond.h
index 087fa56..a1987c4 100644
--- a/be/src/olap/olap_cond.h
+++ b/be/src/olap/olap_cond.h
@@ -150,6 +150,9 @@ public:
     typedef std::map<int32_t, CondColumn*> CondColumns;
 
     Conditions() {}
+    ~Conditions() {
+        finalize();
+    }
 
     void finalize() {
         for (auto& it : _columns) {
diff --git a/be/src/olap/rowset/column_data.cpp b/be/src/olap/rowset/column_data.cpp
index 781b063..0bc9609 100644
--- a/be/src/olap/rowset/column_data.cpp
+++ b/be/src/olap/rowset/column_data.cpp
@@ -43,7 +43,7 @@ ColumnData::ColumnData(SegmentGroup* segment_group)
         _lru_cache = StorageEngine::instance()->index_stream_lru_cache();
     } else {
         // for independent usage, eg: unit test/segment tool
-        _lru_cache = new_lru_cache(config::index_stream_cache_capacity);
+        _lru_cache = FileHandler::get_fd_cache();
     }
     _num_rows_per_block = _segment_group->get_num_rows_per_row_block();
 }
diff --git a/be/src/olap/rowset/segment_v2/encoding_info.cpp b/be/src/olap/rowset/segment_v2/encoding_info.cpp
index a98d2c6..5993d15 100644
--- a/be/src/olap/rowset/segment_v2/encoding_info.cpp
+++ b/be/src/olap/rowset/segment_v2/encoding_info.cpp
@@ -165,8 +165,15 @@ public:
     Status get(FieldType data_type, EncodingTypePB encoding_type, const EncodingInfo** out);
 
 private:
+    // Not thread-safe
     template<FieldType type, EncodingTypePB encoding_type, bool optimize_value_seek = false>
     void _add_map() {
+        auto key = std::make_pair(type, encoding_type);
+        auto it = _encoding_map.find(key);
+        if (it != _encoding_map.end()) {
+            return;
+        }
+
         EncodingTraits<type, encoding_type> traits;
         std::unique_ptr<EncodingInfo> encoding(new EncodingInfo(traits));
         if (_default_encoding_type_map.find(type) == std::end(_default_encoding_type_map)) {
@@ -175,7 +182,6 @@ private:
         if (optimize_value_seek && _value_seek_encoding_map.find(type) == _value_seek_encoding_map.end()) {
             _value_seek_encoding_map[type] = encoding_type;
         }
-        auto key = std::make_pair(type, encoding_type);
         _encoding_map.emplace(key, encoding.release());
     }
 
diff --git a/be/src/olap/rowset_graph.cpp b/be/src/olap/rowset_graph.cpp
index bca4811..cb59ea0 100644
--- a/be/src/olap/rowset_graph.cpp
+++ b/be/src/olap/rowset_graph.cpp
@@ -66,19 +66,14 @@ OLAPStatus RowsetGraph::construct_rowset_graph(const std::vector<RowsetMetaShare
         int64_t start_vertex_index = _vertex_index_map[rs_metas[i]->start_version()];
         int64_t end_vertex_index = _vertex_index_map[rs_metas[i]->end_version() + 1];
         // Add one edge from start_version to end_version.
-        std::list<int64_t>* edges = _version_graph[start_vertex_index].edges;
-        edges->insert(edges->begin(), end_vertex_index);
+        _version_graph[start_vertex_index].edges.push_front(end_vertex_index);
         // Add reverse edge from end_version to start_version.
-        std::list<int64_t>* r_edges = _version_graph[end_vertex_index].edges;
-        r_edges->insert(r_edges->begin(), start_vertex_index);
+        _version_graph[end_vertex_index].edges.push_front(start_vertex_index);
     }
     return OLAP_SUCCESS;
 }
 
 OLAPStatus RowsetGraph::reconstruct_rowset_graph(const std::vector<RowsetMetaSharedPtr>& rs_metas) {
-    for (auto& vertex : _version_graph) {
-        SAFE_DELETE(vertex.edges);
-    }
     _version_graph.clear();
     _vertex_index_map.clear();
     return construct_rowset_graph(rs_metas);
@@ -107,12 +102,10 @@ OLAPStatus RowsetGraph::add_version_to_graph(const Version& version) {
 
     // We assume this version is new version, so we just add two edges
     // into version graph. add one edge from start_version to end_version
-    std::list<int64_t>* edges = _version_graph[start_vertex_index].edges;
-    edges->insert(edges->begin(), end_vertex_index);
+    _version_graph[start_vertex_index].edges.push_front(end_vertex_index);
 
     // We add reverse edge(from end_version to start_version) to graph
-    std::list<int64_t>* r_edges = _version_graph[end_vertex_index].edges;
-    r_edges->insert(r_edges->begin(), start_vertex_index);
+    _version_graph[end_vertex_index].edges.push_front(start_vertex_index);
 
     return OLAP_SUCCESS;
 }
@@ -131,8 +124,8 @@ OLAPStatus RowsetGraph::delete_version_from_graph(const Version& version) {
     int64_t start_vertex_index = _vertex_index_map[start_vertex_value];
     int64_t end_vertex_index = _vertex_index_map[end_vertex_value];
     // Remove edge and its reverse edge.
-    _version_graph[start_vertex_index].edges->remove(end_vertex_index);
-    _version_graph[end_vertex_index].edges->remove(start_vertex_index);
+    _version_graph[start_vertex_index].edges.remove(end_vertex_index);
+    _version_graph[end_vertex_index].edges.remove(start_vertex_index);
 
     return OLAP_SUCCESS;
 }
@@ -144,9 +137,7 @@ OLAPStatus RowsetGraph::_add_vertex_to_graph(int64_t vertex_value) {
         return OLAP_SUCCESS;
     }
 
-    std::unique_ptr<std::list<int64_t>> edges(new std::list<int64_t>());
-    Vertex vertex = {vertex_value, edges.release()};
-    _version_graph.emplace_back(vertex);
+    _version_graph.emplace_back(Vertex(vertex_value));
     _vertex_index_map[vertex_value] = _version_graph.size() - 1;
     return OLAP_SUCCESS;
 }
@@ -205,18 +196,17 @@ OLAPStatus RowsetGraph::capture_consistent_versions(const Version& spec_version,
     while (bfs_queue.empty() == false && visited[end_vertex_index] == false) {
         int64_t top_vertex_index = bfs_queue.front();
         bfs_queue.pop();
-        auto it = _version_graph[top_vertex_index].edges->begin();
-        for (; it != _version_graph[top_vertex_index].edges->end(); ++it) {
-            if (visited[*it] == false) {
+        for (const auto& it : _version_graph[top_vertex_index].edges) {
+            if (visited[it] == false) {
                 // If we don't support reverse version in the path, and start vertex
                 // value is larger than the end vertex value, we skip this edge.
-                if (_version_graph[top_vertex_index].value > _version_graph[*it].value) {
+                if (_version_graph[top_vertex_index].value > _version_graph[it].value) {
                     continue;
                 }
 
-                visited[*it] = true;
-                predecessor[*it] = top_vertex_index;
-                bfs_queue.push(*it);
+                visited[it] = true;
+                predecessor[it] = top_vertex_index;
+                bfs_queue.push(it);
             }
         }
     }
diff --git a/be/src/olap/storage_engine.cpp b/be/src/olap/storage_engine.cpp
index a8c8967..9892a24 100644
--- a/be/src/olap/storage_engine.cpp
+++ b/be/src/olap/storage_engine.cpp
@@ -157,9 +157,6 @@ OLAPStatus StorageEngine::_open() {
 
     RETURN_NOT_OK(_check_file_descriptor_number());
 
-    auto cache = new_lru_cache(config::file_descriptor_cache_capacity);
-    FileHandler::set_fd_cache(cache);
-
     _index_stream_lru_cache = new_lru_cache(config::index_stream_cache_capacity);
 
     auto dirs = get_stores<false>();
@@ -457,9 +454,6 @@ bool StorageEngine::_delete_tablets_on_unused_root_path() {
 }
 
 void StorageEngine::_clear() {
-    // 删除lru中所有内容,其实进程退出这么做本身意义不大,但对单测和更容易发现问题还是有很大意义的
-    delete FileHandler::get_fd_cache();
-    FileHandler::set_fd_cache(nullptr);
     SAFE_DELETE(_index_stream_lru_cache);
 
     std::lock_guard<std::mutex> l(_store_lock);
diff --git a/be/src/plugin/plugin_loader.cpp b/be/src/plugin/plugin_loader.cpp
index dd2f77f..32c0d2a 100644
--- a/be/src/plugin/plugin_loader.cpp
+++ b/be/src/plugin/plugin_loader.cpp
@@ -191,4 +191,4 @@ Status BuiltinPluginLoader::uninstall() {
     return Status::OK();
 }
 
-}
\ No newline at end of file
+}
diff --git a/be/src/plugin/plugin_loader.h b/be/src/plugin/plugin_loader.h
index b0765fc..1ce3f93 100644
--- a/be/src/plugin/plugin_loader.h
+++ b/be/src/plugin/plugin_loader.h
@@ -34,7 +34,7 @@ public:
     
     PluginLoader(const std::string& name, int type): _name(name), _type(type), _close(false) {}
     
-    ~PluginLoader() {};
+    virtual ~PluginLoader() {};
     
     virtual Status install() = 0;
     
@@ -75,7 +75,7 @@ public:
                                                            _install_path(install_path), _plugin_handler(nullptr) {
     };
 
-    ~DynamicPluginLoader() {
+    virtual ~DynamicPluginLoader() {
         // just close plugin, but don't clean install path (maybe other plugin has used)
         WARN_IF_ERROR(close_plugin(), "close plugin failed.");
     };
@@ -104,7 +104,7 @@ class BuiltinPluginLoader : public PluginLoader {
 public:
     BuiltinPluginLoader(const std::string& name, int type, const Plugin* plugin);
     
-    ~BuiltinPluginLoader() {
+    virtual ~BuiltinPluginLoader() {
         WARN_IF_ERROR(uninstall(), "close plugin failed.");
     }
 
diff --git a/be/src/plugin/plugin_mgr.cpp b/be/src/plugin/plugin_mgr.cpp
index 295470a..7837903 100644
--- a/be/src/plugin/plugin_mgr.cpp
+++ b/be/src/plugin/plugin_mgr.cpp
@@ -31,7 +31,6 @@ using namespace strings;
     }   \
 }
 
-
 Status PluginMgr::install_plugin(const TPluginMetaInfo& info) {
     {
         std::lock_guard<std::mutex> l(_lock);
diff --git a/be/src/runtime/runtime_state.cpp b/be/src/runtime/runtime_state.cpp
index 90479fd..0ee816e 100644
--- a/be/src/runtime/runtime_state.cpp
+++ b/be/src/runtime/runtime_state.cpp
@@ -151,6 +151,10 @@ RuntimeState::~RuntimeState() {
         _buffer_reservation->Close();
     }
 
+    if (_exec_env != nullptr) {
+        _exec_env->thread_mgr()->unregister_pool(_resource_pool);
+    }
+
 #ifndef BE_TEST
     // _query_mem_tracker must be valid as long as _instance_mem_tracker is so
     // delete _instance_mem_tracker first.
diff --git a/be/src/runtime/thread_resource_mgr.cpp b/be/src/runtime/thread_resource_mgr.cpp
index 4b3a6ac..30f2566 100644
--- a/be/src/runtime/thread_resource_mgr.cpp
+++ b/be/src/runtime/thread_resource_mgr.cpp
@@ -44,6 +44,15 @@ ThreadResourceMgr::ThreadResourceMgr() {
     _per_pool_quota = 0;
 }
 
+ThreadResourceMgr::~ThreadResourceMgr() {
+    for (auto pool : _free_pool_objs) {
+        delete pool;
+    }
+    for (auto pool : _pools) {
+        delete pool;
+    }
+}
+
 ThreadResourceMgr::ResourcePool::ResourcePool(ThreadResourceMgr* parent)
     : _parent(parent) {
 }
diff --git a/be/src/runtime/thread_resource_mgr.h b/be/src/runtime/thread_resource_mgr.h
index 67835bf..2106b61 100644
--- a/be/src/runtime/thread_resource_mgr.h
+++ b/be/src/runtime/thread_resource_mgr.h
@@ -195,6 +195,7 @@ public:
     // based on the hardware.
     ThreadResourceMgr(int threads_quota);
     ThreadResourceMgr();
+    ~ThreadResourceMgr();
 
     int system_threads_quota() const {
         return _system_threads_quota;
diff --git a/be/src/util/block_compression.cpp b/be/src/util/block_compression.cpp
index 8bddfc6..cc631e1 100644
--- a/be/src/util/block_compression.cpp
+++ b/be/src/util/block_compression.cpp
@@ -342,7 +342,12 @@ public:
         }
 
         output->size = zstrm.total_out;
-
+        zres = deflateEnd(&zstrm);
+        if (zres != Z_OK) {
+            return Status::InvalidArgument(
+                    Substitute("Fail to do deflateEnd on ZLib stream, error=$0, res=$1",
+                               zError(zres), zres));
+        }
         return Status::OK();
     }
 
diff --git a/be/src/util/debug/leak_annotations.h b/be/src/util/debug/leak_annotations.h
new file mode 100644
index 0000000..fa05ee4
--- /dev/null
+++ b/be/src/util/debug/leak_annotations.h
@@ -0,0 +1,85 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+#ifndef DORIS_UTIL_DEBUG_LEAK_ANNOTATIONS_H_
+#define DORIS_UTIL_DEBUG_LEAK_ANNOTATIONS_H_
+
+// Ignore a single leaked object, given its pointer.
+// Does nothing if LeakSanitizer is not enabled.
+#define ANNOTATE_LEAKING_OBJECT_PTR(p)
+
+#if defined(__has_feature)
+#  if __has_feature(address_sanitizer)
+#    if defined(__linux__)
+
+#undef ANNOTATE_LEAKING_OBJECT_PTR
+#define ANNOTATE_LEAKING_OBJECT_PTR(p) __lsan_ignore_object(p);
+
+#    endif
+#  endif
+#endif
+
+// API definitions from LLVM lsan_interface.h
+
+extern "C" {
+  // Allocations made between calls to __lsan_disable() and __lsan_enable() will
+  // be treated as non-leaks. Disable/enable pairs may be nested.
+  void __lsan_disable();
+  void __lsan_enable();
+
+  // The heap object into which p points will be treated as a non-leak.
+  void __lsan_ignore_object(const void *p);
+
+  // The user may optionally provide this function to disallow leak checking
+  // for the program it is linked into (if the return value is non-zero). This
+  // function must be defined as returning a constant value; any behavior beyond
+  // that is unsupported.
+  int __lsan_is_turned_off();
+
+  // Check for leaks now. This function behaves identically to the default
+  // end-of-process leak check. In particular, it will terminate the process if
+  // leaks are found and the exitcode runtime flag is non-zero.
+  // Subsequent calls to this function will have no effect and end-of-process
+  // leak check will not run. Effectively, end-of-process leak check is moved to
+  // the time of first invocation of this function.
+  // By calling this function early during process shutdown, you can instruct
+  // LSan to ignore shutdown-only leaks which happen later on.
+  void __lsan_do_leak_check();
+
+  // Check for leaks now. Returns zero if no leaks have been found or if leak
+  // detection is disabled, non-zero otherwise.
+  // This function may be called repeatedly, e.g. to periodically check a
+  // long-running process. It prints a leak report if appropriate, but does not
+  // terminate the process. It does not affect the behavior of
+  // __lsan_do_leak_check() or the end-of-process leak check, and is not
+  // affected by them.
+  int __lsan_do_recoverable_leak_check();
+} // extern "C"
+
+namespace doris {
+namespace debug {
+
+class ScopedLSANDisabler {
+ public:
+  ScopedLSANDisabler() { __lsan_disable(); }
+  ~ScopedLSANDisabler() { __lsan_enable(); }
+};
+
+} // namespace debug
+} // namespace doris
+
+#endif  // DORIS_UTIL_DEBUG_LEAK_ANNOTATIONS_H_
+
diff --git a/be/src/olap/fs/fs_util.cpp b/be/src/util/debug/leakcheck_disabler.h
similarity index 58%
copy from be/src/olap/fs/fs_util.cpp
copy to be/src/util/debug/leakcheck_disabler.h
index b3d504b..ccb682e 100644
--- a/be/src/olap/fs/fs_util.cpp
+++ b/be/src/util/debug/leakcheck_disabler.h
@@ -14,33 +14,32 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
+#ifndef DORIS_UTIL_DEBUG_LEAKCHECK_DISABLER_H_
+#define DORIS_UTIL_DEBUG_LEAKCHECK_DISABLER_H_
 
-#include "olap/fs/fs_util.h"
-
-#include "common/status.h"
-#include "env/env.h"
-#include "olap/storage_engine.h"
-#include "olap/fs/file_block_manager.h"
-#include "runtime/exec_env.h"
+#include "gutil/macros.h"
+#include "util/debug/leak_annotations.h"
 
 namespace doris {
-namespace fs {
-namespace fs_util {
-
-BlockManager* block_manager() {
-#ifdef BE_TEST
-    return block_mgr_for_ut();
-#else
-    return ExecEnv::GetInstance()->storage_engine()->block_manager();
+namespace debug {
+
+// Scoped object that generically disables LSAN leak checking in a given scope.
+// While this object is alive, calls to "new" will not be checked for leaks.
+class ScopedLeakCheckDisabler {
+ public:
+  ScopedLeakCheckDisabler() {}
+
+ private:
+
+#ifdef LEAK_SANITIZER
+  ScopedLSANDisabler lsan_disabler;
 #endif
-}
 
-BlockManager* block_mgr_for_ut() {
-    fs::BlockManagerOptions bm_opts;
-    bm_opts.read_only = false;
-    return new FileBlockManager(Env::Default(), std::move(bm_opts));
-}
+  DISALLOW_COPY_AND_ASSIGN(ScopedLeakCheckDisabler);
+};
 
-} // namespace fs_util
-} // namespace fs
+} // namespace debug
 } // namespace doris
+
+#endif // DORIS_UTIL_DEBUG_LEAKCHECK_DISABLER_H_
+
diff --git a/be/src/util/doris_metrics.cpp b/be/src/util/doris_metrics.cpp
index ce35bdf..11fe885 100644
--- a/be/src/util/doris_metrics.cpp
+++ b/be/src/util/doris_metrics.cpp
@@ -136,9 +136,6 @@ IntGauge DorisMetrics::blocks_open_writing;
 
 IntCounter DorisMetrics::blocks_push_remote_duration_us;
 
-DorisMetrics::DorisMetrics() : _metrics(nullptr), _system_metrics(nullptr) {
-}
-
 DorisMetrics::~DorisMetrics() {
     delete _system_metrics;
     delete _metrics;
@@ -150,6 +147,10 @@ void DorisMetrics::initialize(
         bool init_system_metrics,
         const std::set<std::string>& disk_devices,
         const std::vector<std::string>& network_interfaces) {
+    if (_metrics != nullptr) {
+        return;
+    }
+    DCHECK(_metrics == nullptr && _system_metrics == nullptr);
     _metrics = new MetricRegistry(name);
 #define REGISTER_DORIS_METRIC(name) _metrics->register_metric(#name, &name)
 
diff --git a/be/src/util/doris_metrics.h b/be/src/util/doris_metrics.h
index cd9a2d0..e755b76 100644
--- a/be/src/util/doris_metrics.h
+++ b/be/src/util/doris_metrics.h
@@ -167,7 +167,7 @@ public:
     static IntCounter blocks_push_remote_duration_us;
 
     ~DorisMetrics();
-    // call before calling metrics
+    // not thread-safe, call before calling metrics
     void initialize(
         const std::string& name,
         const std::vector<std::string>& paths = std::vector<std::string>(),
@@ -180,7 +180,7 @@ public:
     static SystemMetrics* system_metrics() { return _s_doris_metrics._system_metrics; }
 private:
     // Don't allow constrctor
-    DorisMetrics();
+    DorisMetrics() {}
 
     void update();
     void _update_process_thread_num();
@@ -191,8 +191,8 @@ private:
 
     static DorisMetrics _s_doris_metrics;
 
-    MetricRegistry* _metrics;
-    SystemMetrics* _system_metrics;
+    MetricRegistry* _metrics = nullptr;
+    SystemMetrics* _system_metrics = nullptr;
 };
 
 };
diff --git a/be/src/util/dynamic_util.cpp b/be/src/util/dynamic_util.cpp
index 0c9413c..a8d8ace 100644
--- a/be/src/util/dynamic_util.cpp
+++ b/be/src/util/dynamic_util.cpp
@@ -50,7 +50,11 @@ Status dynamic_open(const char* library, void** handle) {
 }
 
 void dynamic_close(void* handle) {
-    dlclose(handle);
+// There is an issue of LSAN can't deal well with dlclose(), so we disable LSAN here, more details:
+// https://github.com/google/sanitizers/issues/89
+#ifndef LEAK_SANITIZER
+   dlclose(handle);
+#endif
 }
 
 }
diff --git a/be/test/exec/es_predicate_test.cpp b/be/test/exec/es_predicate_test.cpp
index 76fe204..3a436c1 100644
--- a/be/test/exec/es_predicate_test.cpp
+++ b/be/test/exec/es_predicate_test.cpp
@@ -163,6 +163,9 @@ TEST_F(EsPredicateTest, normal) {
     std::string expected_json = "{\"bool\":{\"filter\":[{\"bool\":{\"should\":[{\"range\":{\"id\":{\"gt\":\"10\"}}}]}}]}}";
     LOG(INFO) << "compound bool query" << actual_bool_json;
     ASSERT_STREQ(expected_json.c_str(), actual_bool_json.c_str());
+    for (auto predicate : predicates) {
+        delete predicate;
+    }
 }
 
 
diff --git a/be/test/exec/es_query_builder_test.cpp b/be/test/exec/es_query_builder_test.cpp
index 811f653..f35ec6c 100644
--- a/be/test/exec/es_query_builder_test.cpp
+++ b/be/test/exec/es_query_builder_test.cpp
@@ -27,6 +27,7 @@
 #include "rapidjson/stringbuffer.h"
 #include "rapidjson/writer.h"
 #include "runtime/string_value.h"
+#include "util/debug/leakcheck_disabler.h"
 
 namespace doris {
 
@@ -251,6 +252,11 @@ TEST_F(BooleanQueryBuilderTest, bool_query) {
     std::string expected_json = "{\"bool\":{\"should\":[{\"wildcard\":{\"content\":\"a*e*g?\"}},{\"bool\":{\"must_not\":{\"exists\":{\"field\":\"f1\"}}}},{\"range\":{\"k\":{\"gte\":\"a\"}}},{\"term\":{\"content\":\"wyf\"}}]}}";
     //LOG(INFO) << "bool query" << actual_json;
     ASSERT_STREQ(expected_json.c_str(), actual_json.c_str());
+
+    delete like_predicate;
+    delete function_predicate;
+    delete range_predicate;
+    delete term_predicate;
 }
 
 TEST_F(BooleanQueryBuilderTest, compound_bool_query) {
@@ -275,6 +281,7 @@ TEST_F(BooleanQueryBuilderTest, compound_bool_query) {
     std::vector<ExtLiteral> es_query_values = {es_query_term_literal};
     std::string function_name = "esquery";
     ExtFunction* function_predicate = new ExtFunction(TExprNodeType::FUNCTION_CALL, function_name, es_query_cols, es_query_values);
+
     std::vector<ExtPredicate*> bool_predicates_1 = {like_predicate, function_predicate};
     EsPredicate* bool_predicate_1 = new EsPredicate(bool_predicates_1);
 
@@ -335,7 +342,12 @@ TEST_F(BooleanQueryBuilderTest, compound_bool_query) {
     std::string expected_json = "{\"bool\":{\"filter\":[{\"bool\":{\"should\":[{\"wildcard\":{\"content\":\"a*e*g?\"}},{\"bool\":{\"must_not\":{\"exists\":{\"field\":\"f1\"}}}}]}},{\"bool\":{\"should\":[{\"range\":{\"k\":{\"gte\":\"a\"}}}]}},{\"bool\":{\"should\":[{\"bool\":{\"must_not\":[{\"term\":{\"content\":\"wyf\"}}]}}]}},{\"bool\":{\"should\":[{\"bool\":{\"must_not\":[{\"terms\":{\"fv\":[\"8.0\",\"16.0\"]}}]}}]}}]}}";
     //LOG(INFO) << "compound bool query" << actual_bool_json;
     ASSERT_STREQ(expected_json.c_str(), actual_bool_json.c_str());
+    delete bool_predicate_1;
+    delete bool_predicate_2;
+    delete bool_predicate_3;
+    delete bool_predicate_4;
 }
+
 TEST_F(BooleanQueryBuilderTest, validate_esquery) {
     std::string function_name = "esquery";
     char field[] = "random";
@@ -387,6 +399,8 @@ TEST_F(BooleanQueryBuilderTest, validate_esquery) {
 }
 
 TEST_F(BooleanQueryBuilderTest, validate_partial) {
+    // TODO(yingchun): LSAN will report some errors in this scope, we should improve the code and enable LSAN later.
+    debug::ScopedLeakCheckDisabler disable_lsan;
     char like_value[] = "a%e%g_";
     int like_value_length = (int)strlen(like_value);
     TypeDescriptor like_type_desc = TypeDescriptor::create_varchar_type(like_value_length);
@@ -455,7 +469,7 @@ TEST_F(BooleanQueryBuilderTest, validate_partial) {
     std::vector<bool> result;
     BooleanQueryBuilder::validate(and_bool_predicates, &result);
     std::vector<bool> expected = {true, true, true};
-    ASSERT_TRUE(result == expected);
+    ASSERT_EQ(result, expected);
     char illegal_query[] = "{\"term\": {\"k1\" : \"2\"},\"match\": {\"k1\": \"3\"}}";
     int illegal_query_length = (int)strlen(illegal_query);
     StringValue illegal_query_value(illegal_query, illegal_query_length);
@@ -468,13 +482,14 @@ TEST_F(BooleanQueryBuilderTest, validate_partial) {
     std::vector<bool> result1;
     BooleanQueryBuilder::validate(and_bool_predicates_1, &result1);
     std::vector<bool> expected1 = {true, true, false};
-    ASSERT_TRUE(result1 == expected1);
+    ASSERT_EQ(result1, expected1);
 }
 
 // ( k >= "a" and (fv not in [8.0, 16.0]) or (content != "wyf") ) or content like "a%e%g_"
 
 TEST_F(BooleanQueryBuilderTest, validate_compound_and) {
-
+    // TODO(yingchun): LSAN will report some errors in this scope, we should improve the code and enable LSAN later.
+    debug::ScopedLeakCheckDisabler disable_lsan;
     std::string terms_in_field = "fv"; // fv not in [8.0, 16.0]
     int terms_in_field_length = terms_in_field.length();
     TypeDescriptor terms_in_col_type_desc = TypeDescriptor::create_varchar_type(terms_in_field_length);
diff --git a/be/test/exec/es_scan_node_test.cpp b/be/test/exec/es_scan_node_test.cpp
index 0f6eab5..c56848f 100644
--- a/be/test/exec/es_scan_node_test.cpp
+++ b/be/test/exec/es_scan_node_test.cpp
@@ -134,7 +134,8 @@ TEST_F(EsScanNodeTest, normal_use) {
 
     status = scan_node.open(&_runtime_state);
     ASSERT_TRUE(status.ok());
-    RowBatch row_batch(scan_node._row_descriptor, _runtime_state.batch_size(), new MemTracker(-1));
+    std::unique_ptr<MemTracker> mem_tracker(new MemTracker(-1));
+    RowBatch row_batch(scan_node._row_descriptor, _runtime_state.batch_size(), mem_tracker.get());
     bool eos = false;
     status = scan_node.get_next(&_runtime_state, &row_batch, &eos);
     ASSERT_TRUE(status.ok());
diff --git a/be/test/exec/plain_text_line_reader_bzip_test.cpp b/be/test/exec/plain_text_line_reader_bzip_test.cpp
index 648d089..3b3a073 100644
--- a/be/test/exec/plain_text_line_reader_bzip_test.cpp
+++ b/be/test/exec/plain_text_line_reader_bzip_test.cpp
@@ -89,6 +89,7 @@ TEST_F(PlainTextLineReaderTest, bzip2_normal_use) {
     st = line_reader.read_line(&ptr, &size, &eof);
     ASSERT_TRUE(st.ok());
     ASSERT_TRUE(eof);
+    delete decompressor;
 }
 
 TEST_F(PlainTextLineReaderTest, bzip2_test_limit) {
@@ -125,6 +126,7 @@ TEST_F(PlainTextLineReaderTest, bzip2_test_limit) {
     st = line_reader.read_line(&ptr, &size, &eof);
     ASSERT_TRUE(st.ok());
     ASSERT_FALSE(eof);
+    delete decompressor;
 }
 
 TEST_F(PlainTextLineReaderTest, bzip2_test_limit2) {
@@ -148,6 +150,7 @@ TEST_F(PlainTextLineReaderTest, bzip2_test_limit2) {
     // Empty
     st = line_reader.read_line(&ptr, &size, &eof);
     ASSERT_TRUE(st.ok());
+    delete decompressor;
 }
 
 TEST_F(PlainTextLineReaderTest, bzip2_test_limit3) {
@@ -177,6 +180,7 @@ TEST_F(PlainTextLineReaderTest, bzip2_test_limit3) {
     // Empty
     st = line_reader.read_line(&ptr, &size, &eof);
     ASSERT_TRUE(st.ok());
+    delete decompressor;
 }
 
 TEST_F(PlainTextLineReaderTest, bzip2_test_limit4) {
@@ -206,6 +210,7 @@ TEST_F(PlainTextLineReaderTest, bzip2_test_limit4) {
     // Empty
     st = line_reader.read_line(&ptr, &size, &eof);
     ASSERT_TRUE(st.ok());
+    delete decompressor;
 }
 
 TEST_F(PlainTextLineReaderTest, bzip2_test_limit5) {
@@ -225,6 +230,7 @@ TEST_F(PlainTextLineReaderTest, bzip2_test_limit5) {
     // Empty
     st = line_reader.read_line(&ptr, &size, &eof);
     ASSERT_TRUE(st.ok());
+    delete decompressor;
 }
 
 } // end namespace doris
diff --git a/be/test/exec/plain_text_line_reader_gzip_test.cpp b/be/test/exec/plain_text_line_reader_gzip_test.cpp
index 27ca2cb..2c2f3f6 100644
--- a/be/test/exec/plain_text_line_reader_gzip_test.cpp
+++ b/be/test/exec/plain_text_line_reader_gzip_test.cpp
@@ -89,6 +89,7 @@ TEST_F(PlainTextLineReaderTest, gzip_normal_use) {
     st = line_reader.read_line(&ptr, &size, &eof);
     ASSERT_TRUE(st.ok());
     ASSERT_TRUE(eof);
+    delete decompressor;
 }
 
 TEST_F(PlainTextLineReaderTest, uncompressed_no_newline) {
@@ -123,6 +124,7 @@ TEST_F(PlainTextLineReaderTest, uncompressed_no_newline) {
     st = line_reader.read_line(&ptr, &size, &eof);
     ASSERT_TRUE(st.ok());
     ASSERT_TRUE(eof);
+    delete decompressor;
 }
 
 TEST_F(PlainTextLineReaderTest, gzip_test_limit) {
@@ -158,6 +160,7 @@ TEST_F(PlainTextLineReaderTest, gzip_test_limit) {
 
     st = line_reader.read_line(&ptr, &size, &eof);
     ASSERT_TRUE(st.ok());
+    delete decompressor;
 }
 
 TEST_F(PlainTextLineReaderTest, gzip_test_limit2) {
@@ -182,6 +185,7 @@ TEST_F(PlainTextLineReaderTest, gzip_test_limit2) {
     st = line_reader.read_line(&ptr, &size, &eof);
     ASSERT_TRUE(st.ok());
     ASSERT_FALSE(eof);
+    delete decompressor;
 }
 
 TEST_F(PlainTextLineReaderTest, gzip_test_limit3) {
@@ -211,6 +215,7 @@ TEST_F(PlainTextLineReaderTest, gzip_test_limit3) {
     // Empty
     st = line_reader.read_line(&ptr, &size, &eof);
     ASSERT_TRUE(st.ok());
+    delete decompressor;
 }
 
 TEST_F(PlainTextLineReaderTest, gzip_test_limit4) {
@@ -240,6 +245,7 @@ TEST_F(PlainTextLineReaderTest, gzip_test_limit4) {
     // Empty
     st = line_reader.read_line(&ptr, &size, &eof);
     ASSERT_TRUE(st.ok());
+    delete decompressor;
 }
 
 TEST_F(PlainTextLineReaderTest, gzip_test_limit5) {
@@ -259,6 +265,7 @@ TEST_F(PlainTextLineReaderTest, gzip_test_limit5) {
     // Empty
     st = line_reader.read_line(&ptr, &size, &eof);
     ASSERT_TRUE(st.ok());
+    delete decompressor;
 }
 
 } // end namespace doris
diff --git a/be/test/exec/plain_text_line_reader_lz4frame_test.cpp b/be/test/exec/plain_text_line_reader_lz4frame_test.cpp
index e54617a..1c7a544 100644
--- a/be/test/exec/plain_text_line_reader_lz4frame_test.cpp
+++ b/be/test/exec/plain_text_line_reader_lz4frame_test.cpp
@@ -89,6 +89,7 @@ TEST_F(PlainTextLineReaderTest, lz4_normal_use) {
     st = line_reader.read_line(&ptr, &size, &eof);
     ASSERT_TRUE(st.ok());
     ASSERT_TRUE(eof);
+    delete decompressor;
 }
 
 TEST_F(PlainTextLineReaderTest, lz4_test_limit) {
@@ -125,6 +126,7 @@ TEST_F(PlainTextLineReaderTest, lz4_test_limit) {
     st = line_reader.read_line(&ptr, &size, &eof);
     ASSERT_TRUE(st.ok());
     ASSERT_FALSE(eof);
+    delete decompressor;
 }
 
 TEST_F(PlainTextLineReaderTest, lz4_test_limit2) {
@@ -148,6 +150,7 @@ TEST_F(PlainTextLineReaderTest, lz4_test_limit2) {
     // Empty
     st = line_reader.read_line(&ptr, &size, &eof);
     ASSERT_TRUE(st.ok());
+    delete decompressor;
 }
 
 TEST_F(PlainTextLineReaderTest, lz4_test_limit3) {
@@ -177,6 +180,7 @@ TEST_F(PlainTextLineReaderTest, lz4_test_limit3) {
     // Empty
     st = line_reader.read_line(&ptr, &size, &eof);
     ASSERT_TRUE(st.ok());
+    delete decompressor;
 }
 
 TEST_F(PlainTextLineReaderTest, lz4_test_limit4) {
@@ -206,6 +210,7 @@ TEST_F(PlainTextLineReaderTest, lz4_test_limit4) {
     // Empty
     st = line_reader.read_line(&ptr, &size, &eof);
     ASSERT_TRUE(st.ok());
+    delete decompressor;
 }
 
 TEST_F(PlainTextLineReaderTest, lz4_test_limit5) {
@@ -225,6 +230,7 @@ TEST_F(PlainTextLineReaderTest, lz4_test_limit5) {
     // Empty
     st = line_reader.read_line(&ptr, &size, &eof);
     ASSERT_TRUE(st.ok());
+    delete decompressor;
 }
 
 } // end namespace doris
diff --git a/be/test/exec/tablet_sink_test.cpp b/be/test/exec/tablet_sink_test.cpp
index aff3653..bef0794 100644
--- a/be/test/exec/tablet_sink_test.cpp
+++ b/be/test/exec/tablet_sink_test.cpp
@@ -32,6 +32,7 @@
 #include "service/brpc.h"
 #include "util/brpc_stub_cache.h"
 #include "util/cpu_info.h"
+#include "util/debug/leakcheck_disabler.h"
 #include "runtime/descriptor_helper.h"
 #include "runtime/bufferpool/reservation_tracker.h"
 #include "runtime/exec_env.h"
@@ -58,15 +59,13 @@ public:
 
         config::tablet_writer_open_rpc_timeout_sec = 60;
     }
+
     void TearDown() override {
-        delete _env->_brpc_stub_cache;
-        _env->_brpc_stub_cache = nullptr;
-        delete _env->_load_stream_mgr;
-        _env->_load_stream_mgr = nullptr;
-        delete _env->_master_info;
-        _env->_master_info = nullptr;
-        delete _env->_thread_mgr;
-        _env->_thread_mgr = nullptr;
+        SAFE_DELETE(_env->_brpc_stub_cache);
+        SAFE_DELETE(_env->_load_stream_mgr);
+        SAFE_DELETE(_env->_master_info);
+        SAFE_DELETE(_env->_thread_mgr);
+        SAFE_DELETE(_env->_buffer_reservation);
     }
 private:
     ExecEnv* _env;
@@ -335,7 +334,10 @@ TEST_F(OlapTableSinkTest, normal) {
     auto service = new TestInternalService();
     server->AddService(service, brpc::SERVER_OWNS_SERVICE);
     brpc::ServerOptions options;
-    server->Start(4356, &options);
+    {
+        debug::ScopedLeakCheckDisabler disable_lsan;
+        server->Start(4356, &options);
+    }
 
     TUniqueId fragment_id;
     TQueryOptions query_options;
@@ -443,7 +445,10 @@ TEST_F(OlapTableSinkTest, convert) {
     auto service = new TestInternalService();
     server->AddService(service, brpc::SERVER_OWNS_SERVICE);
     brpc::ServerOptions options;
-    server->Start(4356, &options);
+    {
+        debug::ScopedLeakCheckDisabler disable_lsan;
+        server->Start(4356, &options);
+    }
 
     TUniqueId fragment_id;
     TQueryOptions query_options;
@@ -754,7 +759,10 @@ TEST_F(OlapTableSinkTest, add_batch_failed) {
     auto service = new TestInternalService();
     server->AddService(service, brpc::SERVER_OWNS_SERVICE);
     brpc::ServerOptions options;
-    server->Start(4356, &options);
+    {
+        debug::ScopedLeakCheckDisabler disable_lsan;
+        server->Start(4356, &options);
+    }
 
     TUniqueId fragment_id;
     TQueryOptions query_options;
@@ -849,7 +857,10 @@ TEST_F(OlapTableSinkTest, decimal) {
     auto service = new TestInternalService();
     server->AddService(service, brpc::SERVER_OWNS_SERVICE);
     brpc::ServerOptions options;
-    server->Start(4356, &options);
+    {
+        debug::ScopedLeakCheckDisabler disable_lsan;
+        server->Start(4356, &options);
+    }
 
     TUniqueId fragment_id;
     TQueryOptions query_options;
diff --git a/be/test/exprs/percentile_approx_test.cpp b/be/test/exprs/percentile_approx_test.cpp
index 7b9b642..650ae5b 100644
--- a/be/test/exprs/percentile_approx_test.cpp
+++ b/be/test/exprs/percentile_approx_test.cpp
@@ -46,6 +46,7 @@ TEST_F(PercentileApproxTest, testSample) {
     AggregateFunctions::percentile_approx_merge(context, s, &stringVal2);
     DoubleVal v = AggregateFunctions::percentile_approx_finalize(context, stringVal2);
     ASSERT_EQ(v.val, 2);
+    delete futil;
 }
 
 TEST_F(PercentileApproxTest, testNoMerge) {
@@ -63,6 +64,7 @@ TEST_F(PercentileApproxTest, testNoMerge) {
 
     DoubleVal v = AggregateFunctions::percentile_approx_finalize(context, stringVal1);
     ASSERT_EQ(v.val, 2);
+    delete futil;
 }
 
 TEST_F(PercentileApproxTest, testSerialize) {
@@ -85,6 +87,7 @@ TEST_F(PercentileApproxTest, testSerialize) {
     AggregateFunctions::percentile_approx_merge(context, serialized, &stringVal2);
     DoubleVal v = AggregateFunctions::percentile_approx_finalize(context, stringVal2);
     ASSERT_DOUBLE_EQ(v.val, 99900.5);
+    delete futil;
 }
 
 TEST_F(PercentileApproxTest, testNullVale) {
@@ -110,6 +113,7 @@ TEST_F(PercentileApproxTest, testNullVale) {
     AggregateFunctions::percentile_approx_merge(context, serialized, &stringVal2);
     DoubleVal v = AggregateFunctions::percentile_approx_finalize(context, stringVal2);
     ASSERT_FLOAT_EQ(v.val, 99900.665999999997);
+    delete futil;
 }
 
 }
diff --git a/be/test/exprs/string_functions_test.cpp b/be/test/exprs/string_functions_test.cpp
index 059bb89..a9b76e6 100644
--- a/be/test/exprs/string_functions_test.cpp
+++ b/be/test/exprs/string_functions_test.cpp
@@ -45,6 +45,7 @@ TEST_F(StringFunctionsTest, money_format_bigint) {
     result = StringFunctions::money_format(context, doris_udf::BigIntVal(9223372036854775807));
     expected = AnyValUtil::from_string_temp(context, std::string("9,223,372,036,854,775,807.00"));
     ASSERT_EQ(expected, result);
+    delete context;
 }
 
 TEST_F(StringFunctionsTest, money_format_large_int) {
@@ -61,6 +62,7 @@ TEST_F(StringFunctionsTest, money_format_large_int) {
     StringVal result = StringFunctions::money_format(context, doris_udf::LargeIntVal(value));
     StringVal expected = AnyValUtil::from_string_temp(context, std::string("170,141,183,460,469,231,731,687,303,715,884,105,727.00"));
     ASSERT_EQ(expected, result);
+    delete context;
 }
 
 TEST_F(StringFunctionsTest, money_format_double) {
@@ -81,6 +83,7 @@ TEST_F(StringFunctionsTest, money_format_double) {
     result = StringFunctions::money_format(context, doris_udf::DoubleVal(1234.454));
     expected = AnyValUtil::from_string_temp(context, std::string("1,234.45"));
     ASSERT_EQ(expected, result);
+    delete context;
 }
 
 TEST_F(StringFunctionsTest, money_format_decimal) {
@@ -101,6 +104,7 @@ TEST_F(StringFunctionsTest, money_format_decimal) {
     result = StringFunctions::money_format(context, value2);
     expected = AnyValUtil::from_string_temp(context, std::string("-7,407,407,406,790,123,456.72"));
     ASSERT_EQ(expected, result);
+    delete context;
 }
 
 TEST_F(StringFunctionsTest, money_format_decimal_v2) {
@@ -121,6 +125,7 @@ TEST_F(StringFunctionsTest, money_format_decimal_v2) {
     result = StringFunctions::money_format(context, value2);
     expected = AnyValUtil::from_string_temp(context, std::string("-740,740,740.72"));
     ASSERT_EQ(expected, result);
+    delete context;
 }
 
 TEST_F(StringFunctionsTest, split_part) {
@@ -155,6 +160,7 @@ TEST_F(StringFunctionsTest, split_part) {
 
     ASSERT_EQ(AnyValUtil::from_string_temp(context,std::string("")),
             StringFunctions::split_part(context, StringVal("abcdabda"), StringVal("a"), 4));
+    delete context;
 }
 
 TEST_F(StringFunctionsTest, ends_with) {
@@ -188,6 +194,7 @@ TEST_F(StringFunctionsTest, ends_with) {
     ASSERT_EQ(nullRet, StringFunctions::ends_with(context, StringVal::null(), StringVal("hello")));
 
     ASSERT_EQ(nullRet, StringFunctions::ends_with(context, StringVal::null(), StringVal::null()));
+    delete context;
 }
 
 TEST_F(StringFunctionsTest, starts_with) {
@@ -221,6 +228,7 @@ TEST_F(StringFunctionsTest, starts_with) {
     ASSERT_EQ(nullRet, StringFunctions::starts_with(context, StringVal::null(), StringVal("hello world")));
 
     ASSERT_EQ(nullRet, StringFunctions::starts_with(context, StringVal::null(), StringVal::null()));
+    delete context;
 }
 
 TEST_F(StringFunctionsTest, null_or_empty) {
@@ -241,6 +249,7 @@ TEST_F(StringFunctionsTest, null_or_empty) {
     ASSERT_EQ(falseRet, StringFunctions::null_or_empty(context, StringVal(".")));
 
     ASSERT_EQ(trueRet, StringFunctions::null_or_empty(context, StringVal::null()));
+    delete context;
 }
 
 }
diff --git a/be/test/exprs/timestamp_functions_test.cpp b/be/test/exprs/timestamp_functions_test.cpp
index a79ac17..c176a1f 100644
--- a/be/test/exprs/timestamp_functions_test.cpp
+++ b/be/test/exprs/timestamp_functions_test.cpp
@@ -66,6 +66,7 @@ TEST_F(TimestampFunctionsTest, day_of_week_test) {
     tv.type = TIME_DATETIME;
 
     ASSERT_EQ(7, TimestampFunctions::day_of_week(context, tv).val);
+    delete context;
 }
 
 TEST_F(TimestampFunctionsTest, time_diff_test) {
@@ -120,6 +121,7 @@ TEST_F(TimestampFunctionsTest, convert_tz_test) {
     t = TimestampFunctions::convert_tz(context, tv1, StringVal("CST"), StringVal("America/Los_Angeles"));
     DateTimeValue dt3 = DateTimeValue::from_datetime_val(t);
     ASSERT_EQ(20190806013857, dt3.to_int64());
+    delete context;
 }
 
 TEST_F(TimestampFunctionsTest, timestampdiff_test) {
@@ -171,6 +173,7 @@ TEST_F(TimestampFunctionsTest, timestampdiff_test) {
     ASSERT_EQ(8639, TimestampFunctions::minutes_diff(context, tv2, tv1).val);
     //SECOND
     ASSERT_EQ(518399, TimestampFunctions::seconds_diff(context, tv2, tv1).val);
+    delete context;
 }
 
 }
diff --git a/be/test/http/stream_load_test.cpp b/be/test/http/stream_load_test.cpp
index 142e339..ee96e0a 100644
--- a/be/test/http/stream_load_test.cpp
+++ b/be/test/http/stream_load_test.cpp
@@ -112,6 +112,7 @@ TEST_F(StreamLoadActionTest, no_auth) {
     StreamLoadAction action(&_env);
 
     HttpRequest request(_evhttp_req);
+    request.set_handler(&action);
     action.on_header(&request);
     action.handle(&request);
 
@@ -127,6 +128,7 @@ TEST_F(StreamLoadActionTest, no_content_length) {
 
     HttpRequest request(_evhttp_req);
     request._headers.emplace(HttpHeaders::AUTHORIZATION, "Basic cm9vdDo=");
+    request.set_handler(&action);
     action.on_header(&request);
     action.handle(&request);
 
@@ -142,6 +144,7 @@ TEST_F(StreamLoadActionTest, unknown_encoding) {
     HttpRequest request(_evhttp_req);
     request._headers.emplace(HttpHeaders::AUTHORIZATION, "Basic cm9vdDo=");
     request._headers.emplace(HttpHeaders::TRANSFER_ENCODING, "chunked111");
+    request.set_handler(&action);
     action.on_header(&request);
     action.handle(&request);
 
@@ -163,6 +166,7 @@ TEST_F(StreamLoadActionTest, normal) {
 
     request._headers.emplace(HttpHeaders::AUTHORIZATION, "Basic cm9vdDo=");
     request._headers.emplace(HttpHeaders::CONTENT_LENGTH, "0");
+    request.set_handler(&action);
     action.on_header(&request);
     action.handle(&request);
 
@@ -185,6 +189,7 @@ TEST_F(StreamLoadActionTest, put_fail) {
     request._headers.emplace(HttpHeaders::CONTENT_LENGTH, "16");
     Status status= Status::InternalError("TestFail");
     status.to_thrift(&k_stream_load_put_result.status);
+    request.set_handler(&action);
     action.on_header(&request);
     action.handle(&request);
 
@@ -205,6 +210,7 @@ TEST_F(StreamLoadActionTest, commit_fail) {
     request._headers.emplace(HttpHeaders::CONTENT_LENGTH, "16");
     Status status = Status::InternalError("TestFail");
     status.to_thrift(&k_stream_load_commit_result.status);
+    request.set_handler(&action);
     action.on_header(&request);
     action.handle(&request);
 
@@ -225,6 +231,7 @@ TEST_F(StreamLoadActionTest, begin_fail) {
     request._headers.emplace(HttpHeaders::CONTENT_LENGTH, "16");
     Status status = Status::InternalError("TestFail");
     status.to_thrift(&k_stream_load_begin_result.status);
+    request.set_handler(&action);
     action.on_header(&request);
     action.handle(&request);
 
@@ -241,6 +248,7 @@ TEST_F(StreamLoadActionTest, receive_failed) {
     HttpRequest request(_evhttp_req);
     request._headers.emplace(HttpHeaders::AUTHORIZATION, "Basic cm9vdDo=");
     request._headers.emplace(HttpHeaders::TRANSFER_ENCODING, "chunked");
+    request.set_handler(&action);
     action.on_header(&request);
     action.handle(&request);
 
@@ -261,6 +269,7 @@ TEST_F(StreamLoadActionTest, plan_fail) {
     request._headers.emplace(HttpHeaders::AUTHORIZATION, "Basic cm9vdDo=");
     request._headers.emplace(HttpHeaders::CONTENT_LENGTH, "16");
     k_stream_load_plan_status = Status::InternalError("TestFail");
+    request.set_handler(&action);
     action.on_header(&request);
     action.handle(&request);
 
diff --git a/be/test/olap/bloom_filter_test.cpp b/be/test/olap/bloom_filter_test.cpp
index c77dff0..0bfa51c 100644
--- a/be/test/olap/bloom_filter_test.cpp
+++ b/be/test/olap/bloom_filter_test.cpp
@@ -74,6 +74,7 @@ TEST_F(TestBloomFilter, init_bloom_filter) {
         ASSERT_EQ(0, bf.bit_num());
         ASSERT_EQ(0, bf.hash_function_num());
         ASSERT_EQ(NULL, bf.bit_set_data());
+        delete[] data;
     }
 }
 
diff --git a/be/test/olap/column_reader_test.cpp b/be/test/olap/column_reader_test.cpp
index ace23d5..0627b9c 100644
--- a/be/test/olap/column_reader_test.cpp
+++ b/be/test/olap/column_reader_test.cpp
@@ -42,18 +42,6 @@ public:
             _column_reader(NULL),
             _stream_factory(NULL) {
             _offsets.clear();
-        _map_in_streams.clear();
-
-        _present_buffers.clear();
-        
-        _data_buffers.clear();
-
-        _second_buffers.clear();
-
-        _dictionary_buffers.clear();
-
-        _length_buffers.clear();
-
         _mem_tracker.reset(new MemTracker(-1));
         _mem_pool.reset(new MemPool(_mem_tracker.get()));
     }
@@ -77,25 +65,19 @@ public:
     
     virtual void TearDown() {
         SAFE_DELETE(_column_writer);
-
         SAFE_DELETE(_column_reader);
-
         SAFE_DELETE(_stream_factory);
-        
         SAFE_DELETE(_shared_buffer);
         
         _offsets.clear();
-
+        for (auto in_stream : _map_in_streams) {
+            delete in_stream.second;
+        }
         _map_in_streams.clear();
-
         _present_buffers.clear();
-        
         _data_buffers.clear();
-
         _second_buffers.clear();
-
         _dictionary_buffers.clear();
-
         _length_buffers.clear();
     }
 
@@ -233,7 +215,6 @@ public:
     }
 
     ColumnWriter *_column_writer;
-
     ColumnReader *_column_reader;
     std::unique_ptr<MemTracker> _mem_tracker;
     std::unique_ptr<MemPool> _mem_pool;
@@ -242,23 +223,15 @@ public:
     OutStreamFactory *_stream_factory;
 
     std::vector<size_t> _offsets;
-
     std::vector<StorageByteBuffer*> _present_buffers;
-
     std::vector<StorageByteBuffer*> _data_buffers;
-
     std::vector<StorageByteBuffer*> _second_buffers;
-
     std::vector<StorageByteBuffer*> _dictionary_buffers;
-
     std::vector<StorageByteBuffer*> _length_buffers;
 
     StorageByteBuffer* _shared_buffer;
-
     std::map<StreamName, ReadOnlyFileStream *> _map_in_streams;
-
     FileHandler helper;
-
     OlapReaderStatistics _stats;
 };
 
diff --git a/be/test/olap/comparison_predicate_test.cpp b/be/test/olap/comparison_predicate_test.cpp
index 70e136e..2393a40 100644
--- a/be/test/olap/comparison_predicate_test.cpp
+++ b/be/test/olap/comparison_predicate_test.cpp
@@ -177,6 +177,7 @@ TEST_F(TestEqualPredicate, TYPE_NAME##_COLUMN) { \
     ASSERT_EQ(_vectorized_batch->size(), 1); \
     sel = _vectorized_batch->selected(); \
     ASSERT_EQ(*(col_data + sel[0]), 5); \
+    delete pred; \
 } \
 
 TEST_EQUAL_PREDICATE(int8_t, TINYINT, "TINYINT")
@@ -229,6 +230,7 @@ TEST_F(TestEqualPredicate, FLOAT_COLUMN) {
     ASSERT_EQ(_vectorized_batch->size(), 1);
     sel = _vectorized_batch->selected();
     ASSERT_FLOAT_EQ(*(col_data + sel[0]), 5.0);
+    delete pred;
 }
 
 TEST_F(TestEqualPredicate, DOUBLE_COLUMN) {
@@ -275,6 +277,7 @@ TEST_F(TestEqualPredicate, DOUBLE_COLUMN) {
     ASSERT_EQ(_vectorized_batch->size(), 1);
     sel = _vectorized_batch->selected();
     ASSERT_DOUBLE_EQ(*(col_data + sel[0]), 5.0);
+    delete pred;
 }
 
 TEST_F(TestEqualPredicate, DECIMAL_COLUMN) {
@@ -324,6 +327,7 @@ TEST_F(TestEqualPredicate, DECIMAL_COLUMN) {
     ASSERT_EQ(_vectorized_batch->size(), 1);
     sel = _vectorized_batch->selected();
     ASSERT_EQ(*(col_data + sel[0]), value);
+    delete pred;
 }
 
 TEST_F(TestEqualPredicate, STRING_COLUMN) {
@@ -404,6 +408,8 @@ TEST_F(TestEqualPredicate, STRING_COLUMN) {
     ASSERT_EQ(_vectorized_batch->size(), 1);
     sel = _vectorized_batch->selected();
     ASSERT_EQ(*(col_data + sel[0]), value);
+    delete field;
+    delete pred;
 }
 
 TEST_F(TestEqualPredicate, DATE_COLUMN) {
@@ -465,6 +471,7 @@ TEST_F(TestEqualPredicate, DATE_COLUMN) {
     sel = _vectorized_batch->selected();
     ASSERT_EQ(*(col_data + sel[0]), value);
     ASSERT_EQ(datetime::to_date_string(*(col_data + sel[0])), "2017-09-10");
+    delete pred;
 }
 
 TEST_F(TestEqualPredicate, DATETIME_COLUMN) {
@@ -526,6 +533,7 @@ TEST_F(TestEqualPredicate, DATETIME_COLUMN) {
     sel = _vectorized_batch->selected();
     ASSERT_EQ(*(col_data + sel[0]), value);
     ASSERT_EQ(datetime::to_datetime_string(*(col_data + sel[0])), "2017-09-10 01:00:00");
+    delete pred;
 }
 
 #define TEST_LESS_PREDICATE(TYPE, TYPE_NAME, FIELD_TYPE) \
@@ -581,6 +589,7 @@ TEST_F(TestLessPredicate, TYPE_NAME##_COLUMN) { \
         sum += *(col_data + sel[i]); \
     } \
     ASSERT_EQ(sum, 4); \
+    delete pred; \
 } \
 
 TEST_LESS_PREDICATE(int8_t, TINYINT, "TINYINT")
@@ -642,6 +651,7 @@ TEST_F(TestLessPredicate, FLOAT_COLUMN) {
         sum += *(col_data + sel[i]);
     }
     ASSERT_FLOAT_EQ(sum, 4.0);
+    delete pred;
 }
 
 TEST_F(TestLessPredicate, DOUBLE_COLUMN) {
@@ -697,6 +707,7 @@ TEST_F(TestLessPredicate, DOUBLE_COLUMN) {
         sum += *(col_data + sel[i]);
     }
     ASSERT_DOUBLE_EQ(sum, 4.0);
+    delete pred;
 }
 
 TEST_F(TestLessPredicate, DECIMAL_COLUMN) {
@@ -756,6 +767,7 @@ TEST_F(TestLessPredicate, DECIMAL_COLUMN) {
     }
     ASSERT_EQ(sum.integer, 4);
     ASSERT_EQ(sum.fraction, 4);
+    delete pred;
 }
 
 TEST_F(TestLessPredicate, STRING_COLUMN) {
@@ -820,6 +832,7 @@ TEST_F(TestLessPredicate, STRING_COLUMN) {
     ASSERT_EQ(_vectorized_batch->size(), 1);
     sel = _vectorized_batch->selected();
     ASSERT_TRUE(strncmp((*(col_data + sel[0])).ptr, "bb", 2) == 0);
+    delete pred;
 }
 
 TEST_F(TestLessPredicate, DATE_COLUMN) {
@@ -878,6 +891,7 @@ TEST_F(TestLessPredicate, DATE_COLUMN) {
     ASSERT_EQ(_vectorized_batch->size(), 1);
     sel = _vectorized_batch->selected();
     ASSERT_EQ(datetime::to_date_string(*(col_data + sel[0])), "2017-09-08");
+    delete pred;
 }
 
 TEST_F(TestLessPredicate, DATETIME_COLUMN) {
@@ -937,6 +951,7 @@ TEST_F(TestLessPredicate, DATETIME_COLUMN) {
     ASSERT_EQ(_vectorized_batch->size(), 1);
     sel = _vectorized_batch->selected();
     ASSERT_EQ(datetime::to_datetime_string(*(col_data + sel[0])), "2017-09-08 00:01:00");
+    delete pred;
 }
 
 } // namespace doris
diff --git a/be/test/olap/delete_handler_test.cpp b/be/test/olap/delete_handler_test.cpp
index f78b329..7407a90 100644
--- a/be/test/olap/delete_handler_test.cpp
+++ b/be/test/olap/delete_handler_test.cpp
@@ -56,6 +56,8 @@ void set_up() {
     paths.emplace_back(config::storage_root_path, -1);
     config::min_file_descriptor_number = 1000;
     config::tablet_map_shard_size = 1;
+    config::txn_map_shard_size = 1;
+    config::txn_shard_size = 1;
 
     doris::EngineOptions options;
     options.store_paths = paths;
diff --git a/be/test/olap/in_list_predicate_test.cpp b/be/test/olap/in_list_predicate_test.cpp
index f1b43c2..f1809b2 100644
--- a/be/test/olap/in_list_predicate_test.cpp
+++ b/be/test/olap/in_list_predicate_test.cpp
@@ -183,6 +183,7 @@ TEST_F(TestInListPredicate, TYPE_NAME##_COLUMN) { \
     ASSERT_EQ(_vectorized_batch->size(), 1); \
     sel = _vectorized_batch->selected(); \
     ASSERT_EQ(*(col_data + sel[0]), 5); \
+    delete pred; \
 } \
 
 TEST_IN_LIST_PREDICATE(int8_t, TINYINT, "TINYINT")
@@ -247,6 +248,7 @@ TEST_F(TestInListPredicate, TYPE_NAME##_COLUMN_V2) { \
     pred->evaluate(&column2, sel, &selected_size); \
     ASSERT_EQ(selected_size, 1); \
     ASSERT_EQ(*((TYPE*)column2.cell_ptr(sel[0])), 5); \
+    delete pred; \
 } \
 
 TEST_IN_LIST_PREDICATE_V2(int8_t, TINYINT, "TINYINT")
@@ -304,6 +306,7 @@ TEST_F(TestInListPredicate, FLOAT_COLUMN) {
     ASSERT_EQ(_vectorized_batch->size(), 1);
     sel = _vectorized_batch->selected();
     ASSERT_FLOAT_EQ(*(col_data + sel[0]), 5.1);
+    delete pred;
 }
 
 TEST_F(TestInListPredicate, DOUBLE_COLUMN) {
@@ -356,6 +359,7 @@ TEST_F(TestInListPredicate, DOUBLE_COLUMN) {
     ASSERT_EQ(_vectorized_batch->size(), 1);
     sel = _vectorized_batch->selected();
     ASSERT_DOUBLE_EQ(*(col_data + sel[0]), 5.1);
+    delete pred;
 }
 
 TEST_F(TestInListPredicate, DECIMAL_COLUMN) {
@@ -417,6 +421,7 @@ TEST_F(TestInListPredicate, DECIMAL_COLUMN) {
     ASSERT_EQ(_vectorized_batch->size(), 1);
     sel = _vectorized_batch->selected();
     ASSERT_EQ(*(col_data + sel[0]), value2);
+    delete pred;
 }
 
 TEST_F(TestInListPredicate, CHAR_COLUMN) {
@@ -500,6 +505,7 @@ TEST_F(TestInListPredicate, CHAR_COLUMN) {
     ASSERT_EQ(_vectorized_batch->size(), 1);
     sel = _vectorized_batch->selected();
     ASSERT_EQ(*(col_data + sel[0]), value2);
+    delete pred;
 }
 
 TEST_F(TestInListPredicate, VARCHAR_COLUMN) {
@@ -581,6 +587,7 @@ TEST_F(TestInListPredicate, VARCHAR_COLUMN) {
     ASSERT_EQ(_vectorized_batch->size(), 1);
     sel = _vectorized_batch->selected();
     ASSERT_EQ(*(col_data + sel[0]), value2);
+    delete pred;
 }
 
 TEST_F(TestInListPredicate, DATE_COLUMN) {
@@ -650,6 +657,7 @@ TEST_F(TestInListPredicate, DATE_COLUMN) {
     ASSERT_EQ(_vectorized_batch->size(), 1);
     sel = _vectorized_batch->selected();
     ASSERT_EQ(datetime::to_date_string(*(col_data + sel[0])), "2017-09-10");
+    delete pred;
 }
 
 TEST_F(TestInListPredicate, DATETIME_COLUMN) {
@@ -719,6 +727,7 @@ TEST_F(TestInListPredicate, DATETIME_COLUMN) {
     ASSERT_EQ(_vectorized_batch->size(), 1);
     sel = _vectorized_batch->selected();
     ASSERT_EQ(datetime::to_datetime_string(*(col_data + sel[0])), "2017-09-10 01:00:00");
+    delete pred;
 }
 
 } // namespace doris
diff --git a/be/test/olap/null_predicate_test.cpp b/be/test/olap/null_predicate_test.cpp
index f59b4a5..4be0f8d 100644
--- a/be/test/olap/null_predicate_test.cpp
+++ b/be/test/olap/null_predicate_test.cpp
@@ -141,6 +141,7 @@ TEST_F(TestNullPredicate, TYPE_NAME##_COLUMN) { \
     _vectorized_batch->set_selected_in_use(false); \
     pred->evaluate(_vectorized_batch); \
     ASSERT_EQ(_vectorized_batch->size(), 5); \
+    delete pred; \
 } \
 
 TEST_IN_LIST_PREDICATE(int8_t, TINYINT, "TINYINT")
@@ -188,6 +189,7 @@ TEST_F(TestNullPredicate, FLOAT_COLUMN) {
     _vectorized_batch->set_selected_in_use(false);
     pred->evaluate(_vectorized_batch);
     ASSERT_EQ(_vectorized_batch->size(), 5);
+    delete pred;
 }
 
 TEST_F(TestNullPredicate, DOUBLE_COLUMN) {
@@ -230,6 +232,7 @@ TEST_F(TestNullPredicate, DOUBLE_COLUMN) {
     _vectorized_batch->set_selected_in_use(false);
     pred->evaluate(_vectorized_batch);
     ASSERT_EQ(_vectorized_batch->size(), 5);
+    delete pred;
 }
 
 TEST_F(TestNullPredicate, DECIMAL_COLUMN) {
@@ -275,6 +278,7 @@ TEST_F(TestNullPredicate, DECIMAL_COLUMN) {
     _vectorized_batch->set_selected_in_use(false);
     pred->evaluate(_vectorized_batch);
     ASSERT_EQ(_vectorized_batch->size(), 4);
+    delete pred;
 }
 
 TEST_F(TestNullPredicate, STRING_COLUMN) {
@@ -330,6 +334,7 @@ TEST_F(TestNullPredicate, STRING_COLUMN) {
     _vectorized_batch->set_selected_in_use(false);
     pred->evaluate(_vectorized_batch);
     ASSERT_EQ(_vectorized_batch->size(), 4);
+    delete pred;
 }
 
 TEST_F(TestNullPredicate, DATE_COLUMN) {
@@ -383,6 +388,7 @@ TEST_F(TestNullPredicate, DATE_COLUMN) {
     _vectorized_batch->set_selected_in_use(false);
     pred->evaluate(_vectorized_batch);
     ASSERT_EQ(_vectorized_batch->size(), 2);
+    delete pred;
 }
 
 TEST_F(TestNullPredicate, DATETIME_COLUMN) {
@@ -436,6 +442,7 @@ TEST_F(TestNullPredicate, DATETIME_COLUMN) {
     _vectorized_batch->set_selected_in_use(false);
     pred->evaluate(_vectorized_batch);
     ASSERT_EQ(_vectorized_batch->size(), 2);
+    delete pred;
 }
 
 } // namespace doris
diff --git a/be/test/olap/olap_snapshot_converter_test.cpp b/be/test/olap/olap_snapshot_converter_test.cpp
index 40abeb2..112756c 100644
--- a/be/test/olap/olap_snapshot_converter_test.cpp
+++ b/be/test/olap/olap_snapshot_converter_test.cpp
@@ -52,6 +52,9 @@ static StorageEngine* k_engine = nullptr;
 class OlapSnapshotConverterTest : public testing::Test {
 public:
     virtual void SetUp() {
+        config::tablet_map_shard_size = 1;
+        config::txn_map_shard_size = 1;
+        config::txn_shard_size = 1;
         std::vector<StorePath> paths;
         paths.emplace_back("_engine_data_path", -1);
         EngineOptions options;
@@ -61,8 +64,6 @@ public:
             k_engine = new StorageEngine(options);
         }
 
-        auto cache = new_lru_cache(config::file_descriptor_cache_capacity);
-        FileHandler::set_fd_cache(cache);
         string test_engine_data_path = "./be/test/olap/test_data/converter_test_data/data";
         _engine_data_path = "./be/test/olap/test_data/converter_test_data/tmp";
         boost::filesystem::remove_all(_engine_data_path);
diff --git a/be/test/olap/rowset/alpha_rowset_test.cpp b/be/test/olap/rowset/alpha_rowset_test.cpp
index 1c26bd3..96fd9f4 100644
--- a/be/test/olap/rowset/alpha_rowset_test.cpp
+++ b/be/test/olap/rowset/alpha_rowset_test.cpp
@@ -181,8 +181,6 @@ TEST_F(AlphaRowsetTest, TestAlphaRowsetWriter) {
     row.set_field_content(2, reinterpret_cast<char*>(&field_2), _mem_pool.get());
     _alpha_rowset_writer->add_row(row);
     _alpha_rowset_writer->flush();
-    auto cache = new_lru_cache(config::file_descriptor_cache_capacity);
-    FileHandler::set_fd_cache(cache);
     RowsetSharedPtr alpha_rowset = _alpha_rowset_writer->build();
     ASSERT_TRUE(alpha_rowset != nullptr);
     RowsetId rowset_id;
@@ -216,8 +214,6 @@ TEST_F(AlphaRowsetTest, TestAlphaRowsetReader) {
     ASSERT_EQ(OLAP_SUCCESS, res);
     res = _alpha_rowset_writer->flush();
     ASSERT_EQ(OLAP_SUCCESS, res);
-    auto cache = new_lru_cache(config::file_descriptor_cache_capacity);
-    FileHandler::set_fd_cache(cache);
     RowsetSharedPtr alpha_rowset = _alpha_rowset_writer->build();
     ASSERT_TRUE(alpha_rowset != nullptr);
     RowsetId rowset_id;
diff --git a/be/test/olap/rowset/beta_rowset_test.cpp b/be/test/olap/rowset/beta_rowset_test.cpp
index 026eccc..bfcad1d 100644
--- a/be/test/olap/rowset/beta_rowset_test.cpp
+++ b/be/test/olap/rowset/beta_rowset_test.cpp
@@ -49,6 +49,9 @@ protected:
     OlapReaderStatistics _stats;
 
     void SetUp() override {
+        config::tablet_map_shard_size = 1;
+        config::txn_map_shard_size = 1;
+        config::txn_shard_size = 1;
         char buffer[MAX_PATH_LEN];
         getcwd(buffer, MAX_PATH_LEN);
         config::storage_root_path = std::string(buffer) + "/data_test";
@@ -339,6 +342,7 @@ TEST_F(BetaRowsetTest, BasicFunctionTest) {
             EXPECT_EQ(OLAP_ERR_DATA_EOF, s);
             EXPECT_TRUE(output_block == nullptr);
             EXPECT_EQ(100, num_rows_read);
+            delete predicate;
         }
     }
 }
diff --git a/be/test/olap/rowset/rowset_converter_test.cpp b/be/test/olap/rowset/rowset_converter_test.cpp
index 40360a0..daf7577 100644
--- a/be/test/olap/rowset/rowset_converter_test.cpp
+++ b/be/test/olap/rowset/rowset_converter_test.cpp
@@ -150,6 +150,9 @@ void create_tablet_meta(TabletSchema* tablet_schema, TabletMeta* tablet_meta) {
 class RowsetConverterTest : public testing::Test {
 public:
     virtual void SetUp() {
+        config::tablet_map_shard_size = 1;
+        config::txn_map_shard_size = 1;
+        config::txn_shard_size = 1;
         config::path_gc_check = false;
         char buffer[MAX_PATH_LEN];
         getcwd(buffer, MAX_PATH_LEN);
@@ -161,7 +164,9 @@ public:
 
         doris::EngineOptions options;
         options.store_paths = paths;
-        doris::StorageEngine::open(options, &k_engine);
+        if (k_engine == nullptr) {
+            doris::StorageEngine::open(options, &k_engine);
+        }
 
         ExecEnv* exec_env = doris::ExecEnv::GetInstance();
         exec_env->set_storage_engine(k_engine);
@@ -212,8 +217,6 @@ void RowsetConverterTest::process(RowsetTypePB src_type, RowsetTypePB dst_type)
         _rowset_writer->add_row(row);
     }
     _rowset_writer->flush();
-    auto cache = new_lru_cache(config::file_descriptor_cache_capacity);
-    FileHandler::set_fd_cache(cache);
     RowsetSharedPtr src_rowset = _rowset_writer->build();
     ASSERT_TRUE(src_rowset != nullptr);
     RowsetId src_rowset_id;
diff --git a/be/test/olap/rowset/rowset_meta_manager_test.cpp b/be/test/olap/rowset/rowset_meta_manager_test.cpp
index 55a0fd8..8cbc272 100644
--- a/be/test/olap/rowset/rowset_meta_manager_test.cpp
+++ b/be/test/olap/rowset/rowset_meta_manager_test.cpp
@@ -45,7 +45,9 @@ const std::string rowset_meta_path = "./be/test/olap/test_data/rowset_meta.json"
 class RowsetMetaManagerTest : public testing::Test {
 public:
     virtual void SetUp() {
-
+        config::tablet_map_shard_size = 1;
+        config::txn_map_shard_size = 1;
+        config::txn_shard_size = 1;
         std::vector<StorePath> paths;
         paths.emplace_back("_engine_data_path", -1);
         EngineOptions options;
diff --git a/be/test/olap/rowset/segment_v2/bitmap_index_test.cpp b/be/test/olap/rowset/segment_v2/bitmap_index_test.cpp
index af0a46b..d83bf59 100644
--- a/be/test/olap/rowset/segment_v2/bitmap_index_test.cpp
+++ b/be/test/olap/rowset/segment_v2/bitmap_index_test.cpp
@@ -136,6 +136,7 @@ TEST_F(BitmapIndexTest, test_invert) {
         delete reader;
         delete iter;
     }
+    delete val;
 }
 
 TEST_F(BitmapIndexTest, test_invert_2) {
@@ -173,6 +174,7 @@ TEST_F(BitmapIndexTest, test_invert_2) {
         delete reader;
         delete iter;
     }
+    delete val;
 }
 
 TEST_F(BitmapIndexTest, test_multi_pages) {
@@ -204,6 +206,7 @@ TEST_F(BitmapIndexTest, test_multi_pages) {
         delete reader;
         delete iter;
     }
+    delete val;
 }
 
 TEST_F(BitmapIndexTest, test_null) {
@@ -228,6 +231,7 @@ TEST_F(BitmapIndexTest, test_null) {
         delete reader;
         delete iter;
     }
+    delete val;
 }
 
 }
diff --git a/be/test/olap/rowset/segment_v2/zone_map_index_test.cpp b/be/test/olap/rowset/segment_v2/zone_map_index_test.cpp
index 290142e..d3c5ff5 100644
--- a/be/test/olap/rowset/segment_v2/zone_map_index_test.cpp
+++ b/be/test/olap/rowset/segment_v2/zone_map_index_test.cpp
@@ -150,6 +150,7 @@ TEST_F(ColumnZoneMapTest, NormalTestIntPage) {
 
     ASSERT_EQ(true, zone_maps[2].has_null());
     ASSERT_EQ(false, zone_maps[2].has_not_null());
+    delete field;
 }
 
 // Test for string
@@ -157,6 +158,7 @@ TEST_F(ColumnZoneMapTest, NormalTestVarcharPage) {
     TabletColumn varchar_column = create_varchar_key(0);
     Field* field = FieldFactory::create(varchar_column);
     test_string("NormalTestVarcharPage", field);
+    delete field;
 }
 
 // Test for string
@@ -164,6 +166,7 @@ TEST_F(ColumnZoneMapTest, NormalTestCharPage) {
     TabletColumn char_column = create_char_key(0);
     Field* field = FieldFactory::create(char_column);
     test_string("NormalTestCharPage", field);
+    delete field;
 }
 
 }
diff --git a/be/test/olap/run_length_byte_test.cpp b/be/test/olap/run_length_byte_test.cpp
index d1a75be..155f3b2 100755
--- a/be/test/olap/run_length_byte_test.cpp
+++ b/be/test/olap/run_length_byte_test.cpp
@@ -79,11 +79,10 @@ TEST(TestStream, UncompressOutStream2) {
     ASSERT_EQ(out_stream->output_buffers().size(), 2);
 
     std::vector<StorageByteBuffer*> inputs;
-    std::vector<StorageByteBuffer*>::const_iterator it = out_stream->output_buffers().begin();
-    for (; it != out_stream->output_buffers().end(); ++it) {
-        StorageByteBuffer *tmp_byte_buffer = StorageByteBuffer::reference_buffer(*it, 0, (*it)->limit());
-        inputs.push_back(tmp_byte_buffer);
+    for (const auto& it : out_stream->output_buffers()) {
+        inputs.push_back(StorageByteBuffer::reference_buffer(it, 0, it->limit()));
     }
+
     std::vector<uint64_t> offsets;
     offsets.push_back(0);
     offsets.push_back(sizeof(StreamHead) + OLAP_DEFAULT_COLUMN_STREAM_BUFFER_SIZE);
@@ -109,6 +108,9 @@ TEST(TestStream, UncompressOutStream2) {
 
     SAFE_DELETE(out_stream);
     SAFE_DELETE(in_stream);
+    for (auto input : inputs) {
+        delete input;
+    }
 }
 
 TEST(TestStream, UncompressOutStream3) {
@@ -131,10 +133,8 @@ TEST(TestStream, UncompressOutStream3) {
     ASSERT_EQ(out_stream->output_buffers().size(), 2);
 
     std::vector<StorageByteBuffer*> inputs;
-    std::vector<StorageByteBuffer*>::const_iterator it = out_stream->output_buffers().begin();
-    for (; it != out_stream->output_buffers().end(); ++it) {
-        StorageByteBuffer *tmp_byte_buffer = StorageByteBuffer::reference_buffer(*it, 0, (*it)->limit());
-        inputs.push_back(tmp_byte_buffer);
+    for (const auto& it : out_stream->output_buffers()) {
+        inputs.push_back(StorageByteBuffer::reference_buffer(it, 0, it->limit()));
     }
 
     std::vector<uint64_t> offsets;
@@ -161,10 +161,13 @@ TEST(TestStream, UncompressOutStream3) {
 
     ASSERT_NE(in_stream->read(&data), OLAP_SUCCESS);
 
+    SAFE_DELETE(in_stream);
     SAFE_DELETE(out_stream);
+    for (auto input : inputs) {
+        delete input;
+    }
 }
 
-
 TEST(TestStream, UncompressInStream) {
     // write data
     OutStream *out_stream = 
@@ -177,10 +180,9 @@ TEST(TestStream, UncompressInStream) {
 
     // read data
     std::vector<StorageByteBuffer*> inputs;
-    std::vector<StorageByteBuffer*>::const_iterator it = out_stream->output_buffers().begin();
+    const auto& it = out_stream->output_buffers().begin();
     ASSERT_NE(it, out_stream->output_buffers().end());
-    StorageByteBuffer *tmp_byte_buffer = StorageByteBuffer::reference_buffer(*it, 0, (*it)->capacity());
-    inputs.push_back(tmp_byte_buffer);
+    inputs.push_back(StorageByteBuffer::reference_buffer(*it, 0, (*it)->capacity()));
 
     std::vector<uint64_t> offsets;
     offsets.assign(inputs.size(), 0);
@@ -198,6 +200,9 @@ TEST(TestStream, UncompressInStream) {
     ASSERT_EQ(data, 0x5a);
 
     SAFE_DELETE(in_stream);
+    for (auto input : inputs) {
+        delete input;
+    }
 }
 
 // the length after compress must be smaller than origal stream, then the compressor will be called. 
@@ -244,11 +249,10 @@ TEST(TestStream, CompressOutStream2) {
     out_stream->flush();
 
     std::vector<StorageByteBuffer*> inputs;
-    std::vector<StorageByteBuffer*>::const_iterator it = out_stream->output_buffers().begin();
-    for (; it != out_stream->output_buffers().end(); ++it) {
-        StorageByteBuffer *tmp_byte_buffer = StorageByteBuffer::reference_buffer(*it, 0, (*it)->limit());
-        inputs.push_back(tmp_byte_buffer);
+    for (const auto& it : out_stream->output_buffers()) {
+        inputs.push_back(StorageByteBuffer::reference_buffer(it, 0, it->limit()));
     }
+
     std::vector<uint64_t> offsets;
     offsets.push_back(0);
     offsets.push_back(59); // if lzo, this shoudl be 57
@@ -269,7 +273,11 @@ TEST(TestStream, CompressOutStream2) {
 
     ASSERT_NE(in_stream->read(&data), OLAP_SUCCESS);
 
+    SAFE_DELETE(in_stream);
     SAFE_DELETE(out_stream);
+    for (auto input : inputs) {
+        delete input;
+    }
 }
 
 
@@ -291,11 +299,10 @@ TEST(TestStream, CompressOutStream3) {
     out_stream->flush();
 
     std::vector<StorageByteBuffer*> inputs;
-    std::vector<StorageByteBuffer*>::const_iterator it = out_stream->output_buffers().begin();
-    for (; it != out_stream->output_buffers().end(); ++it) {
-        StorageByteBuffer *tmp_byte_buffer = StorageByteBuffer::reference_buffer(*it, 0, (*it)->limit());
-        inputs.push_back(tmp_byte_buffer);
+    for (const auto& it : out_stream->output_buffers()) {
+        inputs.push_back(StorageByteBuffer::reference_buffer(it, 0, it->limit()));
     }
+
     std::vector<uint64_t> offsets;
     offsets.push_back(0);
     offsets.push_back(57);
@@ -318,7 +325,11 @@ TEST(TestStream, CompressOutStream3) {
 
     ASSERT_NE(in_stream->read(&data), OLAP_SUCCESS);
 
+    SAFE_DELETE(in_stream);
     SAFE_DELETE(out_stream);
+    for (auto input : inputs) {
+        delete input;
+    }
 }
 
 //test for _slice() in [while (len > 0 && m_current_range < m_inputs.size())]
@@ -343,11 +354,10 @@ TEST(TestStream, CompressOutStream4) {
     out_stream->flush();
 
     std::vector<StorageByteBuffer*> inputs;
-    std::vector<StorageByteBuffer*>::const_iterator it = out_stream->output_buffers().begin();
-    for (; it != out_stream->output_buffers().end(); ++it) {
-        StorageByteBuffer *tmp_byte_buffer = StorageByteBuffer::reference_buffer(*it, 0, (*it)->limit());
-        inputs.push_back(tmp_byte_buffer);
+    for (const auto& it : out_stream->output_buffers()) {
+        inputs.push_back(StorageByteBuffer::reference_buffer(it, 0, it->limit()));
     }
+
     std::vector<uint64_t> offsets;
     offsets.push_back(0);
     offsets.push_back(16);
@@ -377,7 +387,11 @@ TEST(TestStream, CompressOutStream4) {
 
     ASSERT_NE(in_stream->read(&data), OLAP_SUCCESS);
 
+    SAFE_DELETE(in_stream);
     SAFE_DELETE(out_stream);
+    for (auto input : inputs) {
+        delete input;
+    }
 }
 
 TEST(TestStream, CompressMassOutStream) {
@@ -399,10 +413,8 @@ TEST(TestStream, CompressMassOutStream) {
     out_stream->flush();
 
     std::vector<StorageByteBuffer*> inputs;
-    std::vector<StorageByteBuffer*>::const_iterator it = out_stream->output_buffers().begin();
-    for (; it != out_stream->output_buffers().end(); ++it) {
-        StorageByteBuffer *tmp_byte_buffer = StorageByteBuffer::reference_buffer(*it, 0, (*it)->limit());
-        inputs.push_back(tmp_byte_buffer);
+    for (const auto& it : out_stream->output_buffers()) {
+        inputs.push_back(StorageByteBuffer::reference_buffer(it, 0, it->limit()));
     }
     std::vector<uint64_t> offsets;
     offsets.push_back(0);
@@ -428,6 +440,9 @@ TEST(TestStream, CompressMassOutStream) {
     ASSERT_NE(in_stream->read(&data), OLAP_SUCCESS);
 
     SAFE_DELETE(in_stream);
+    for (auto input : inputs) {
+        delete input;
+    }
 }
 
 TEST(TestStream, CompressInStream) {
@@ -470,6 +485,9 @@ TEST(TestStream, CompressInStream) {
     SAFE_DELETE_ARRAY(write_data);
     SAFE_DELETE(out_stream);
     SAFE_DELETE(in_stream);
+    for (auto input : inputs) {
+        delete input;
+    }
 }
 
 TEST(TestStream, SeekUncompress) {
@@ -526,6 +544,9 @@ TEST(TestStream, SeekUncompress) {
     ASSERT_EQ(data, 0x5b);
     SAFE_DELETE(out_stream);
     SAFE_DELETE(in_stream);
+    for (auto input : inputs) {
+        delete input;
+    }
 }
 
 TEST(TestStream, SkipUncompress) {
@@ -564,6 +585,9 @@ TEST(TestStream, SkipUncompress) {
     ASSERT_EQ(data, write_data[sizeof(write_data)-1]);
     SAFE_DELETE(out_stream);
     SAFE_DELETE(in_stream);
+    for (auto input : inputs) {
+        delete input;
+    }
 }
 
 TEST(TestStream, SeekCompress) {
@@ -616,6 +640,9 @@ TEST(TestStream, SeekCompress) {
     ASSERT_EQ(data, 0x5b);
     SAFE_DELETE(out_stream);
     SAFE_DELETE(in_stream);
+    for (auto input : inputs) {
+        delete input;
+    }
 }
 
 TEST(TestStream, SkipCompress) {
@@ -650,10 +677,12 @@ TEST(TestStream, SkipCompress) {
     char data;
     ASSERT_EQ(in_stream->read(&data), OLAP_SUCCESS);
     ASSERT_EQ(data, 0x5e);
-
-    
+ 
     SAFE_DELETE(out_stream);
     SAFE_DELETE(in_stream);
+    for (auto input : inputs) {
+        delete input;
+    }
 }
 
 class TestRunLengthByte : public testing::Test {
diff --git a/be/test/olap/schema_change_test.cpp b/be/test/olap/schema_change_test.cpp
index 606877b..897e441 100644
--- a/be/test/olap/schema_change_test.cpp
+++ b/be/test/olap/schema_change_test.cpp
@@ -75,6 +75,9 @@ public:
         SAFE_DELETE(_shared_buffer);
 
         _offsets.clear();
+        for (auto in_stream : _map_in_streams) {
+            delete in_stream.second;
+        }
         _map_in_streams.clear();
         _present_buffers.clear();
         _data_buffers.clear();
@@ -106,6 +109,7 @@ public:
         UniqueIdToColumnIdMap segment_included;
         segment_included[0] = 0;
 
+        SAFE_DELETE(_column_reader);
         _column_reader = ColumnReader::create(0,
                                      tablet_schema,
                                      included,
@@ -164,10 +168,16 @@ public:
         ASSERT_EQ(OLAP_SUCCESS, helper.open_with_mode("./ut_dir/tmp_file", 
                 O_RDONLY, S_IRUSR | S_IWUSR)); 
 
+        SAFE_DELETE(_shared_buffer);
         _shared_buffer = StorageByteBuffer::create(
                 OLAP_DEFAULT_COLUMN_STREAM_BUFFER_SIZE + sizeof(StreamHead));
         ASSERT_TRUE(_shared_buffer != NULL);
 
+        for (auto in_stream : _map_in_streams) {
+            delete in_stream.second;
+        }
+        _map_in_streams.clear();
+
         for (int i = 0; i < off.size(); ++i) {
             ReadOnlyFileStream* in_stream = new (std::nothrow) ReadOnlyFileStream(
                     &helper, 
@@ -178,7 +188,6 @@ public:
                     buffer_size[i],
                     &_stats);
             ASSERT_EQ(OLAP_SUCCESS, in_stream->init());
-
             _map_in_streams[name[i]] = in_stream;
         }
 
@@ -564,39 +573,60 @@ TEST_F(TestColumn, ConvertVarcharToDate) {
     ASSERT_EQ(st, OLAP_ERR_INVALID_SCHEMA);
 }
 
-TEST_F(TestColumn, ConvertVarcharToTinyInt) {
+TEST_F(TestColumn, ConvertVarcharToTinyInt1) {
     test_convert_from_varchar("TINYINT", 1, "127", OLAP_SUCCESS);
+}
+
+TEST_F(TestColumn, ConvertVarcharToTinyInt2) {
     test_convert_from_varchar("TINYINT", 1, "128", OLAP_ERR_INVALID_SCHEMA);
 }
 
-TEST_F(TestColumn, ConvertVarcharToSmallInt) {
+TEST_F(TestColumn, ConvertVarcharToSmallInt1) {
     test_convert_from_varchar("SMALLINT", 2, "32767", OLAP_SUCCESS);
+}
+
+TEST_F(TestColumn, ConvertVarcharToSmallInt2) {
     test_convert_from_varchar("SMALLINT", 2, "32768", OLAP_ERR_INVALID_SCHEMA);
 }
 
-TEST_F(TestColumn, ConvertVarcharToInt) {
+TEST_F(TestColumn, ConvertVarcharToInt1) {
     test_convert_from_varchar("INT", 4, "2147483647", OLAP_SUCCESS);
+}
+
+TEST_F(TestColumn, ConvertVarcharToInt2) {
     test_convert_from_varchar("INT", 4, "2147483648", OLAP_ERR_INVALID_SCHEMA);
 }
 
-TEST_F(TestColumn, ConvertVarcharToBigInt) {
+TEST_F(TestColumn, ConvertVarcharToBigInt1) {
     test_convert_from_varchar("BIGINT", 8, "9223372036854775807", OLAP_SUCCESS);
+}
+
+TEST_F(TestColumn, ConvertVarcharToBigInt2) {
     test_convert_from_varchar("BIGINT", 8, "9223372036854775808", OLAP_ERR_INVALID_SCHEMA);
 }
 
-TEST_F(TestColumn, ConvertVarcharToLargeInt) {
+TEST_F(TestColumn, ConvertVarcharToLargeInt1) {
     test_convert_from_varchar("LARGEINT", 16, "170141183460469000000000000000000000000", OLAP_SUCCESS);
+}
+
+TEST_F(TestColumn, ConvertVarcharToLargeInt2) {
     test_convert_from_varchar("LARGEINT", 16, "1701411834604690000000000000000000000000", OLAP_ERR_INVALID_SCHEMA);
 }
 
-TEST_F(TestColumn, ConvertVarcharToFloat) {
+TEST_F(TestColumn, ConvertVarcharToFloat1) {
     test_convert_from_varchar("FLOAT", 4, "3.40282e+38", OLAP_SUCCESS); 
+}
+
+TEST_F(TestColumn, ConvertVarcharToFloat2) {
     test_convert_from_varchar("FLOAT", 4, "1797690000000000063230304921389426434930330364336853362154109832891264341489062899406152996321966094455338163203127744334848599000464911410516510916727344709727599413825823048028128827530592629736371829425359826368844446113768685826367454055532068818593409163400929532301499014067384276511218551077374242324480.999", OLAP_ERR_INVALID_SCHEMA);
 }
 
-TEST_F(TestColumn, ConvertVarcharToDouble) {
+TEST_F(TestColumn, ConvertVarcharToDouble1) {
     test_convert_from_varchar("DOUBLE", 8,
             "123.456", OLAP_SUCCESS);
+}
+
+TEST_F(TestColumn, ConvertVarcharToDouble2) {
     test_convert_from_varchar("DOUBLE", 8,
             "1797690000000000063230304921389426434930330364336853362154109832891264341489062899406152996321966094455338163203127744334848599000464911410516510916727344709727599413825823048028128827530592629736371829425359826368844446113768685826367454055532068818593409163400929532301499014067384276511218551077374242324480.0000000000", OLAP_ERR_INVALID_SCHEMA);
 }
diff --git a/be/test/olap/storage_types_test.cpp b/be/test/olap/storage_types_test.cpp
index 8a11dd5..d4865a3 100644
--- a/be/test/olap/storage_types_test.cpp
+++ b/be/test/olap/storage_types_test.cpp
@@ -113,6 +113,7 @@ void test_char(Slice src_val) {
         ASSERT_FALSE(type->equal((char*)&src_val, (char*)&dst_val));
         ASSERT_TRUE(type->cmp((char*)&src_val, (char*)&dst_val) < 0);
     }
+    delete field;
 }
 
 template<>
diff --git a/be/test/olap/stream_index_test.cpp b/be/test/olap/stream_index_test.cpp
index 2022f04..5f70096 100755
--- a/be/test/olap/stream_index_test.cpp
+++ b/be/test/olap/stream_index_test.cpp
@@ -90,6 +90,7 @@ TEST_F(TestStreamIndex, index_write) {
         ASSERT_EQ(e.positions(1), i * 2);
         ASSERT_EQ(e.positions(2), i * 3);
     }
+    delete[] buffer;
 }
 
 TEST_F(TestStreamIndex, remove_written_position) {
@@ -138,6 +139,7 @@ TEST_F(TestStreamIndex, remove_written_position) {
             ASSERT_EQ(e.positions(1), i * 6);
             ASSERT_EQ(e.positions(2), i * 7);
         }
+        delete[] buffer;
     }
     writer.reset();
 
@@ -182,6 +184,7 @@ TEST_F(TestStreamIndex, remove_written_position) {
             ASSERT_EQ(e.positions(3), i * 6);
             ASSERT_EQ(e.positions(4), i * 7);
         }
+        delete[] buffer;
     }
     writer.reset();
     // test 3
@@ -225,6 +228,7 @@ TEST_F(TestStreamIndex, remove_written_position) {
             ASSERT_EQ(e.positions(3), i * 6);
             ASSERT_EQ(e.positions(4), i * 7);
         }
+        delete[] buffer;
     }
     writer.reset();
     // test 4
@@ -267,6 +271,7 @@ TEST_F(TestStreamIndex, remove_written_position) {
             ASSERT_EQ(e.positions(2), i * 3);
             ASSERT_EQ(e.positions(3 ), i * 4);
         }
+        delete[] buffer;
     }
     writer.reset();
 }
@@ -326,6 +331,7 @@ TEST_F(TestStreamIndex, test_statistic) {
 
     ASSERT_STREQ(stat2.minimum()->to_string().c_str(), "3");
     ASSERT_STREQ(stat2.maximum()->to_string().c_str(), "6");
+    delete field;
 }
 
 TEST_F(TestStreamIndex, statistic) {
@@ -380,6 +386,8 @@ TEST_F(TestStreamIndex, statistic) {
         ASSERT_EQ(e.positions(1), i * 2);
         ASSERT_EQ(e.positions(2), i * 3);
     }
+    delete[] buffer;
+    delete field;
 }
 
 }
diff --git a/be/test/olap/tablet_mgr_test.cpp b/be/test/olap/tablet_mgr_test.cpp
index d78fe60..297de4c 100644
--- a/be/test/olap/tablet_mgr_test.cpp
+++ b/be/test/olap/tablet_mgr_test.cpp
@@ -48,8 +48,9 @@ static StorageEngine* k_engine = nullptr;
 class TabletMgrTest : public testing::Test {
 public:
     virtual void SetUp() {
-        auto cache = new_lru_cache(config::file_descriptor_cache_capacity);
-        FileHandler::set_fd_cache(cache);
+        config::tablet_map_shard_size = 1;
+        config::txn_map_shard_size = 1;
+        config::txn_shard_size = 1;
         string test_engine_data_path = "./be/test/olap/test_data/converter_test_data/data";
         _engine_data_path = "./be/test/olap/test_data/converter_test_data/tmp";
         boost::filesystem::remove_all(_engine_data_path);
diff --git a/be/test/olap/txn_manager_test.cpp b/be/test/olap/txn_manager_test.cpp
index 7725810..4bb2065 100644
--- a/be/test/olap/txn_manager_test.cpp
+++ b/be/test/olap/txn_manager_test.cpp
@@ -93,6 +93,9 @@ public:
     }
 
     virtual void SetUp() {
+        config::tablet_map_shard_size = 1;
+        config::txn_map_shard_size = 1;
+        config::txn_shard_size = 1;
         config::max_runnings_transactions_per_txn_map = 500;
         _txn_mgr.reset(new TxnManager(64, 1024));
         std::vector<StorePath> paths;
diff --git a/be/test/plugin/plugin_mgr_test.cpp b/be/test/plugin/plugin_mgr_test.cpp
index 8b8f216..e80517c 100644
--- a/be/test/plugin/plugin_mgr_test.cpp
+++ b/be/test/plugin/plugin_mgr_test.cpp
@@ -52,8 +52,8 @@ int close_plugin(void* ptr) {
     return 1;
 }
 
-//declare_builtin_plugin(DemoPlugin) {
-Plugin DemoPlugin = {
+//declare_builtin_plugin(demo_plugin) {
+Plugin demo_plugin = {
     nullptr,
     &init_plugin,
     &close_plugin,
@@ -81,7 +81,7 @@ TEST_F(PluginMgrTest, normal) {
 
     PluginMgr mgr;
     
-    mgr.register_builtin_plugin("demo", PLUGIN_TYPE_AUDIT, &DemoPlugin);
+    mgr.register_builtin_plugin("demo", PLUGIN_TYPE_AUDIT, &demo_plugin);
     
     std::shared_ptr<Plugin> re;
     ASSERT_TRUE(mgr.get_plugin("demo", PLUGIN_TYPE_AUDIT, &re).ok());
@@ -94,7 +94,7 @@ TEST_F(PluginMgrTest, normal) {
 
     std::vector<std::shared_ptr<Plugin>> list;
     ASSERT_TRUE(mgr.get_plugin_list(PLUGIN_TYPE_AUDIT, &list).ok());
-    ASSERT_EQ(1, list.size());
+    ASSERT_EQ(1, list.size()); 
 }
 
 }
@@ -102,4 +102,4 @@ TEST_F(PluginMgrTest, normal) {
 int main(int argc, char** argv) {
     ::testing::InitGoogleTest(&argc, argv);
     return RUN_ALL_TESTS();
-}
\ No newline at end of file
+}
diff --git a/be/test/runtime/external_scan_context_mgr_test.cpp b/be/test/runtime/external_scan_context_mgr_test.cpp
index 8cb542f..52d2790 100644
--- a/be/test/runtime/external_scan_context_mgr_test.cpp
+++ b/be/test/runtime/external_scan_context_mgr_test.cpp
@@ -38,6 +38,9 @@ public:
         _exec_env._result_queue_mgr = result_queue_mgr;
     }
     virtual ~ExternalScanContextMgrTest() {
+        delete _exec_env._fragment_mgr;
+        delete _exec_env._thread_mgr;
+        delete _exec_env._result_queue_mgr;
     }
 
 protected:
diff --git a/be/test/runtime/memory_scratch_sink_test.cpp b/be/test/runtime/memory_scratch_sink_test.cpp
index a4fa09d..731c949 100644
--- a/be/test/runtime/memory_scratch_sink_test.cpp
+++ b/be/test/runtime/memory_scratch_sink_test.cpp
@@ -65,6 +65,15 @@ public:
         }
     }
 
+    ~MemoryScratchSinkTest() {
+        delete _state;
+        delete _row_desc;
+        delete _mem_tracker;
+        delete _exec_env->_result_queue_mgr;
+        delete _exec_env->_thread_mgr;
+        delete _exec_env->_buffer_reservation;
+    }
+
     virtual void SetUp() {
         config::periodic_counter_update_period_ms = 500;
         config::storage_root_path = "./data";
@@ -84,19 +93,17 @@ public:
     void init_desc_tbl();
     void init_runtime_state();
 
-    virtual ~MemoryScratchSinkTest() {}
-
 private:
     ObjectPool _obj_pool;
-    ExecEnv* _exec_env;
+    ExecEnv* _exec_env = nullptr;
     // std::vector<TExpr> _exprs;
     TDescriptorTable _t_desc_table;
-    RuntimeState* _state;
+    RuntimeState* _state = nullptr;
     TPlanNode _tnode;
-    RowDescriptor* _row_desc;
+    RowDescriptor* _row_desc = nullptr;
     TMemoryScratchSink _tsink;
-    MemTracker *_mem_tracker;
-    DescriptorTbl* _desc_tbl;
+    MemTracker *_mem_tracker = nullptr;
+    DescriptorTbl* _desc_tbl = nullptr;
     std::vector<TExpr> _exprs;
 };
 
@@ -108,10 +115,8 @@ void MemoryScratchSinkTest::init() {
 }
 
 void MemoryScratchSinkTest::init_runtime_state() {
-    ResultQueueMgr* result_queue_mgr = new ResultQueueMgr();
-    ThreadResourceMgr* thread_mgr = new ThreadResourceMgr();
-    _exec_env->_result_queue_mgr = result_queue_mgr;
-    _exec_env->_thread_mgr = thread_mgr;
+    _exec_env->_result_queue_mgr = new ResultQueueMgr();
+    _exec_env->_thread_mgr = new ThreadResourceMgr();
     _exec_env->_buffer_reservation = new ReservationTracker();
     TQueryOptions query_options;
     query_options.batch_size = 1024;
@@ -232,7 +237,8 @@ TEST_F(MemoryScratchSinkTest, work_flow_normal) {
     status = scan_node.open(_state);
     ASSERT_TRUE(status.ok());
 
-    RowBatch row_batch(scan_node._row_descriptor, _state->batch_size(), new MemTracker(-1));
+    std::unique_ptr<MemTracker> mem_tracker(new MemTracker(-1));
+    RowBatch row_batch(scan_node._row_descriptor, _state->batch_size(), mem_tracker.get());
     bool eos = false;
 
     while (!eos) {
diff --git a/be/test/util/arrow/arrow_work_flow_test.cpp b/be/test/util/arrow/arrow_work_flow_test.cpp
index 0b77655..31744b8 100644
--- a/be/test/util/arrow/arrow_work_flow_test.cpp
+++ b/be/test/util/arrow/arrow_work_flow_test.cpp
@@ -63,6 +63,9 @@ protected:
     virtual void TearDown() {
         _obj_pool.clear();
         system("rm -rf ./test_run");
+
+        delete _state;
+        delete _mem_tracker;
     }
 
     void init();
@@ -72,12 +75,11 @@ protected:
 private:
     ObjectPool _obj_pool;
     TDescriptorTable _t_desc_table;
-    DescriptorTbl* _desc_tbl;
+    DescriptorTbl* _desc_tbl = nullptr;
     TPlanNode _tnode;
-    ExecEnv* _exec_env;
-    RuntimeState* _state;
-    MemTracker *_mem_tracker;
-    RowDescriptor* _row_desc;
+    ExecEnv* _exec_env = nullptr;
+    RuntimeState* _state = nullptr;
+    MemTracker *_mem_tracker = nullptr;
 }; // end class ArrowWorkFlowTest
 
 void ArrowWorkFlowTest::init() {
@@ -87,10 +89,8 @@ void ArrowWorkFlowTest::init() {
 }
 
 void ArrowWorkFlowTest::init_runtime_state() {
-    ResultQueueMgr* result_queue_mgr = new ResultQueueMgr();
-    ThreadResourceMgr* thread_mgr = new ThreadResourceMgr();
-    _exec_env->_result_queue_mgr = result_queue_mgr;
-    _exec_env->_thread_mgr = thread_mgr;
+    _exec_env->_result_queue_mgr = new ResultQueueMgr();
+    _exec_env->_thread_mgr = new ThreadResourceMgr();
     _exec_env->_buffer_reservation = new ReservationTracker();
     TQueryOptions query_options;
     query_options.batch_size = 1024;
@@ -252,7 +252,6 @@ void ArrowWorkFlowTest::init_desc_tbl() {
 
     vector<bool> nullable_tuples;
     nullable_tuples.push_back(false);
-    // _row_desc = _pool.add(new RowDescriptor(*_desc_tbl, row_tids, nullable_tuples));
 
     // node
     _tnode.node_id = 0;
@@ -333,7 +332,8 @@ TEST_F(ArrowWorkFlowTest, NormalUse) {
     status = scan_node.open(_state);
     ASSERT_TRUE(status.ok());
 
-    RowBatch row_batch(scan_node._row_descriptor, _state->batch_size(), new MemTracker(-1));
+    std::unique_ptr<MemTracker> mem_tracker(new MemTracker(-1));
+    RowBatch row_batch(scan_node._row_descriptor, _state->batch_size(), mem_tracker.get());
     bool eos = false;
 
     while (!eos) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org