Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/brpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
#include <google/protobuf/descriptor.h> // ServiceDescriptor
#include "idl_options.pb.h" // option(idl_support)
#include "bthread/unstable.h" // bthread_keytable_pool_init
#include "butil/macros.h" // ARRAY_SIZE
#include "butil/fd_guard.h" // fd_guard
#include "butil/logging.h" // CHECK
#include "butil/macros.h" // ARRAY_SIZE
#include "butil/fd_guard.h" // fd_guard
#include "butil/logging.h" // CHECK
#include "butil/time.h"
#include "butil/class_name.h"
#include "butil/string_printf.h"
#include "butil/debug/leak_annotations.h"
#include "brpc/log.h"
#include "brpc/compress.h"
#include "brpc/policy/nova_pbrpc_protocol.h"
Expand Down Expand Up @@ -885,6 +886,10 @@ int Server::StartInternal(const butil::EndPoint& endpoint,
_session_local_data_pool->Reserve(_options.reserved_session_local_data);
}

// Leak of `_keytable_pool' and others is by design.
// See comments in Server::Join() for details.
// Instruct LeakSanitizer to ignore the designated memory leak.
ANNOTATE_SCOPED_MEMORY_LEAK;
// Init _keytable_pool always. If the server was stopped before, the pool
// should be destroyed in Join().
_keytable_pool = new bthread_keytable_pool_t;
Expand Down
13 changes: 13 additions & 0 deletions src/butil/compiler_specific.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@
#define WARN_UNUSED_RESULT
#endif

// Compiler feature-detection.
// clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension
#if defined(__has_feature)
#define BUTIL_HAS_FEATURE(FEATURE) __has_feature(FEATURE)
#else
#define BUTIL_HAS_FEATURE(FEATURE) 0
#endif

// Instruct ASan is enabled.
#if BUTIL_HAS_FEATURE(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
#define BUTIL_USE_ASAN 1
#endif

// Tell the compiler a function is using a printf-style format string.
// |format_param| is the one-based index of the format string parameter;
// |dots_param| is the one-based index of the "..." parameter.
Expand Down
2 changes: 1 addition & 1 deletion src/butil/debug/leak_annotations.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// ANNOTATE_LEAKING_OBJECT_PTR(X): the heap object referenced by pointer X will
// be annotated as a leak.

#if defined(LEAK_SANITIZER) && !defined(OS_NACL)
#if (defined(LEAK_SANITIZER) && !defined(OS_NACL)) || defined(BUTIL_USE_ASAN)

// Public LSan API from <sanitizer/lsan_interface.h>.
extern "C" {
Expand Down
1 change: 1 addition & 0 deletions src/butil/lazy_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ struct LeakyLazyInstanceTraits {
#endif

static Type* New(void* instance) {
// Instruct LeakSanitizer to ignore the designated memory leak.
ANNOTATE_SCOPED_MEMORY_LEAK;
return DefaultLazyInstanceTraits<Type>::New(instance);
}
Expand Down
11 changes: 9 additions & 2 deletions src/butil/memory/singleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "butil/memory/aligned_memory.h"
#include "butil/third_party/dynamic_annotations/dynamic_annotations.h"
#include "butil/threading/thread_restrictions.h"
#include "butil/debug/leak_annotations.h"

namespace butil {
namespace internal {
Expand Down Expand Up @@ -266,8 +267,14 @@ class Singleton {
butil::subtle::Release_Store(
&instance_, reinterpret_cast<butil::subtle::AtomicWord>(newval));

if (newval != NULL && Traits::kRegisterAtExit)
butil::AtExitManager::RegisterCallback(OnExit, NULL);
if (newval != NULL) {
if (Traits::kRegisterAtExit) {
butil::AtExitManager::RegisterCallback(OnExit, NULL);
} else {
// Instruct LeakSanitizer to ignore the designated memory leak.
ANNOTATE_LEAKING_OBJECT_PTR(newval);
}
}

return newval;
}
Expand Down