Merge pull request #556 from ctiller/codesize

Fix refcounting bug leading to objects not being cleaned up
pull/558/merge
David Klempner 10 years ago
commit 7cffec1e01
  1. 7
      src/core/iomgr/fd_posix.c
  2. 1
      src/core/iomgr/pollset_posix.c

@ -104,14 +104,17 @@ static void destroy(grpc_fd *fd) {
} }
static void ref_by(grpc_fd *fd, int n) { static void ref_by(grpc_fd *fd, int n) {
gpr_atm_no_barrier_fetch_add(&fd->refst, n); GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&fd->refst, n) > 0);
} }
static void unref_by(grpc_fd *fd, int n) { static void unref_by(grpc_fd *fd, int n) {
if (gpr_atm_full_fetch_add(&fd->refst, -n) == n) { gpr_atm old = gpr_atm_full_fetch_add(&fd->refst, -n);
if (old == n) {
grpc_iomgr_add_callback(fd->on_done, fd->on_done_user_data); grpc_iomgr_add_callback(fd->on_done, fd->on_done_user_data);
freelist_fd(fd); freelist_fd(fd);
grpc_iomgr_unref(); grpc_iomgr_unref();
} else {
GPR_ASSERT(old > n);
} }
} }

@ -214,6 +214,7 @@ static void unary_poll_pollset_add_fd(grpc_pollset *pollset, grpc_fd *fd) {
* unary poller */ * unary poller */
grpc_fd_unref(fds[0]); grpc_fd_unref(fds[0]);
pollset->data.ptr = fd; pollset->data.ptr = fd;
grpc_fd_ref(fd);
} }
} }

Loading…
Cancel
Save