From c03496fdacda031c0c4f67e40f38dbbad632f385 Mon Sep 17 00:00:00 2001 From: xtao Date: Fri, 8 Feb 2019 22:36:19 +0800 Subject: [PATCH] 1) remove unnecessary initialization; 2) correct comment grammar issue; 3) fix the newly caught leaks; --- include/grpc/impl/codegen/sync_posix.h | 10 +++++----- src/core/ext/filters/max_age/max_age_filter.cc | 5 ++++- src/core/lib/gpr/sync_posix.cc | 12 +----------- src/core/lib/iomgr/ev_epollex_linux.cc | 1 + src/core/lib/iomgr/ev_poll_posix.cc | 4 ++++ 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/include/grpc/impl/codegen/sync_posix.h b/include/grpc/impl/codegen/sync_posix.h index cf95e4c6345..2aec3a3f8d6 100644 --- a/include/grpc/impl/codegen/sync_posix.h +++ b/include/grpc/impl/codegen/sync_posix.h @@ -26,20 +26,20 @@ #include #ifdef GRPC_ASAN_ENABLED -/* The member |leak_checker| is used to check whether there is memory leak - * that may be caused by upper layer logic which missing the |gpr_xx_destroy| - * call to this object before freeing. +/* The member |leak_checker| is used to check whether there is a memory leak + * caused by upper layer logic that's missing the |gpr_xx_destroy| call + * to the object before freeing it. * This issue was reported at https://github.com/grpc/grpc/issues/17563 * and discussed at https://github.com/grpc/grpc/pull/17586 */ typedef struct { pthread_mutex_t mutex; - int *leak_checker; + int* leak_checker; } gpr_mu; typedef struct { pthread_cond_t cond_var; - int *leak_checker; + int* leak_checker; } gpr_cv; #else typedef pthread_mutex_t gpr_mu; diff --git a/src/core/ext/filters/max_age/max_age_filter.cc b/src/core/ext/filters/max_age/max_age_filter.cc index ec7f4e254aa..f2308581c13 100644 --- a/src/core/ext/filters/max_age/max_age_filter.cc +++ b/src/core/ext/filters/max_age/max_age_filter.cc @@ -499,7 +499,10 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, } /* Destructor for channel_data. */ -static void destroy_channel_elem(grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_channel_element* elem) { + channel_data* chand = static_cast(elem->channel_data); + gpr_mu_destroy(&chand->max_age_timer_mu); +} const grpc_channel_filter grpc_max_age_filter = { grpc_call_next_op, diff --git a/src/core/lib/gpr/sync_posix.cc b/src/core/lib/gpr/sync_posix.cc index a915bbfad95..52745dbff0a 100644 --- a/src/core/lib/gpr/sync_posix.cc +++ b/src/core/lib/gpr/sync_posix.cc @@ -16,8 +16,8 @@ * */ -#include #include +#include #ifdef GPR_POSIX_SYNC @@ -77,11 +77,6 @@ void gpr_mu_init(gpr_mu* mu) { GPR_ASSERT(pthread_mutex_init(&mu->mutex, nullptr) == 0); mu->leak_checker = (int*)gpr_malloc(sizeof(*mu->leak_checker)); GPR_ASSERT(mu->leak_checker != nullptr); - /* Initial it with a magic number, make no sense, just use the memory. - * This only take effect when ASAN enabled, so, - * if memory allocation failed, let it crash. - */ - *mu->leak_checker = 0x12F34D0; #else GPR_ASSERT(pthread_mutex_init(mu, nullptr) == 0); #endif @@ -142,11 +137,6 @@ void gpr_cv_init(gpr_cv* cv) { GPR_ASSERT(pthread_cond_init(&cv->cond_var, &attr) == 0); cv->leak_checker = (int*)gpr_malloc(sizeof(*cv->leak_checker)); GPR_ASSERT(cv->leak_checker != nullptr); - /* Initial it with a magic number, make no sense, just use the memory. - * This only take effect when ASAN enabled, so, - * if memory allocation failed, let it crash. - */ - *cv->leak_checker = 0x12F34D0; #else GPR_ASSERT(pthread_cond_init(cv, &attr) == 0); #endif diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc index 0e66bc56440..27656063ba5 100644 --- a/src/core/lib/iomgr/ev_epollex_linux.cc +++ b/src/core/lib/iomgr/ev_epollex_linux.cc @@ -612,6 +612,7 @@ static void pollable_unref(pollable* p, int line, const char* reason) { close(p->epfd); grpc_wakeup_fd_destroy(&p->wakeup); gpr_mu_destroy(&p->owner_orphan_mu); + gpr_mu_destroy(&p->mu); gpr_free(p); } } diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index c479206410b..9350ef5a2af 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -1535,6 +1535,9 @@ static void cache_harvest_locked() { gpr_inf_future(GPR_CLOCK_MONOTONIC)); } args->poller_thd.Join(); + gpr_cv_destroy(&args->trigger); + gpr_cv_destroy(&args->harvest); + gpr_cv_destroy(&args->join); gpr_free(args); } } @@ -1713,6 +1716,7 @@ static int cvfd_poll(struct pollfd* fds, nfds_t nfds, int timeout) { } gpr_free(fd_cvs); + gpr_cv_destroy(pollcv->cv); gpr_free(pollcv); if (result) { decref_poll_result(result);