1) remove unnecessary initialization;

2) correct comment grammar issue;
3) fix the newly caught leaks;
pull/17939/head
xtao 6 years ago
parent fb3b85a81a
commit c03496fdac
No known key found for this signature in database
GPG Key ID: 87F7A86BDA3A0407
  1. 10
      include/grpc/impl/codegen/sync_posix.h
  2. 5
      src/core/ext/filters/max_age/max_age_filter.cc
  3. 12
      src/core/lib/gpr/sync_posix.cc
  4. 1
      src/core/lib/iomgr/ev_epollex_linux.cc
  5. 4
      src/core/lib/iomgr/ev_poll_posix.cc

@ -26,20 +26,20 @@
#include <pthread.h>
#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;

@ -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<channel_data*>(elem->channel_data);
gpr_mu_destroy(&chand->max_age_timer_mu);
}
const grpc_channel_filter grpc_max_age_filter = {
grpc_call_next_op,

@ -16,8 +16,8 @@
*
*/
#include <grpc/support/port_platform.h>
#include <grpc/support/alloc.h>
#include <grpc/support/port_platform.h>
#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

@ -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);
}
}

@ -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);

Loading…
Cancel
Save