From 4c5a3232e4dbef66df476f064777ba2eef91a29b Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Fri, 4 May 2018 16:33:38 -0700 Subject: [PATCH] Fix db_stress memory leak ASAN error Summary: In case `--expected_values_path` is unset, we allocate a buffer internally to hold the expected DB state. This PR makes sure it is freed. Closes https://github.com/facebook/rocksdb/pull/3804 Differential Revision: D7874694 Pulled By: ajkr fbshipit-source-id: a8f7655e009507c4e639ceebfc3525d69c856e3b --- tools/db_stress.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/db_stress.cc b/tools/db_stress.cc index ce4128052..f291934ba 100644 --- a/tools/db_stress.cc +++ b/tools/db_stress.cc @@ -888,8 +888,9 @@ class SharedState { } } if (values_ == nullptr) { - values_ = - static_cast*>(malloc(expected_values_size)); + values_allocation_.reset( + new std::atomic[FLAGS_column_families * max_key_]); + values_ = &values_allocation_[0]; values_init_needed = true; } assert(values_ != nullptr); @@ -1116,6 +1117,7 @@ class SharedState { std::vector > no_overwrite_ids_; std::atomic* values_; + std::unique_ptr[]> values_allocation_; // Has to make it owned by a smart ptr as port::Mutex is not copyable // and storing it in the container may require copying depending on the impl. std::vector > > key_locks_;