From a53d6d25e09e0cfcaab9993a8321d542e628e083 Mon Sep 17 00:00:00 2001 From: Peter Dillinger Date: Mon, 12 Jul 2021 16:59:22 -0700 Subject: [PATCH] Improve support for valgrind error on reachable (#8503) Summary: MyRocks apparently uses valgrind to check for unreachable unfreed data, which is stricter than our valgrind checks. Internal ref: D29257815 This patch adds valgrind support to STATIC_AVOID_DESTRUCTION so that it's not reported with those stricter checks. Pull Request resolved: https://github.com/facebook/rocksdb/pull/8503 Test Plan: make valgrind_test Also, with modified VALGRIND_OPTS (see Makefile), more kinds of failures seen before than after this commit. Reviewed By: ajkr, yizhang82 Differential Revision: D29597784 Pulled By: pdillinger fbshipit-source-id: 360de157a176aec4d1be99ca20d160ecd47c0873 --- Makefile | 1 + env/env_posix.cc | 2 ++ port/lang.h | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/Makefile b/Makefile index 0669fbcf4..fbf5ecf6f 100644 --- a/Makefile +++ b/Makefile @@ -494,6 +494,7 @@ VALGRIND_ERROR = 2 VALGRIND_VER := $(join $(VALGRIND_VER),valgrind) VALGRIND_OPTS = --error-exitcode=$(VALGRIND_ERROR) --leak-check=full +# Not yet supported: --show-leak-kinds=definite,possible,reachable --errors-for-leak-kinds=definite,possible,reachable TEST_OBJECTS = $(patsubst %.cc, $(OBJ_DIR)/%.o, $(TEST_LIB_SOURCES) $(MOCK_LIB_SOURCES)) $(GTEST) BENCH_OBJECTS = $(patsubst %.cc, $(OBJ_DIR)/%.o, $(BENCH_LIB_SOURCES)) diff --git a/env/env_posix.cc b/env/env_posix.cc index fdcb6f6a3..583c024de 100644 --- a/env/env_posix.cc +++ b/env/env_posix.cc @@ -7,6 +7,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. See the AUTHORS file for names of contributors +#include "port/lang.h" #if !defined(OS_WIN) #include @@ -511,6 +512,7 @@ Env* Env::Default() { ThreadLocalPtr::InitSingletons(); CompressionContextCache::InitSingleton(); INIT_SYNC_POINT_SINGLETONS(); + // ~PosixEnv must be called on exit static PosixEnv default_env; return &default_env; } diff --git a/port/lang.h b/port/lang.h index 4429f105e..eabe44b69 100644 --- a/port/lang.h +++ b/port/lang.h @@ -27,6 +27,10 @@ #endif // __SANITIZE_ADDRESS__ #endif // __clang__ +#ifdef ROCKSDB_VALGRIND_RUN +#define MUST_FREE_HEAP_ALLOCATIONS 1 +#endif // ROCKSDB_VALGRIND_RUN + // Coding guidelines say to avoid static objects with non-trivial destructors, // because it's easy to cause trouble (UB) in static destruction. This // macro makes it easier to define static objects that are normally never