From b11a8b1b9a63bf80d48ce91230115fc721361133 Mon Sep 17 00:00:00 2001 From: Yanqin Jin Date: Thu, 14 May 2020 18:48:06 -0700 Subject: [PATCH] Fix valgrind error by init memory region (#6842) Summary: As title. After allocating a memory buffer, initialize its content to 0s. This fixes valgrind issue introduced in https://github.com/facebook/rocksdb/issues/6709. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6842 Test Plan: ``` $make valgrind_test $valgrind --tool=memcheck --track-origins=yes ./db_test2 --gtest_filter=DBTest2.CompressionFailures ``` Reviewed By: pdillinger Differential Revision: D21551848 Pulled By: riversand963 fbshipit-source-id: e87a6f413e3f3d92d8e23d8ecc4cf93479c6674c --- db/db_test2.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/db/db_test2.cc b/db/db_test2.cc index 59e264ef4..26da04417 100644 --- a/db/db_test2.cc +++ b/db/db_test2.cc @@ -1317,10 +1317,9 @@ TEST_F(DBTest2, CompressionFailures) { if (curr_compression_failure_type == kTestDecompressionCorruption) { BlockContents* contents = static_cast(arg); // Ensure uncompressed data != original data - std::unique_ptr fake_data( - new char[contents->data.size() + 1]); - *contents = - BlockContents(std::move(fake_data), contents->data.size() + 1); + const size_t len = contents->data.size() + 1; + std::unique_ptr fake_data(new char[len]()); + *contents = BlockContents(std::move(fake_data), len); } });