aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/support/sync.c
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2016-03-02 22:17:24 -0800
committerGravatar Craig Tiller <ctiller@google.com>2016-03-02 22:34:23 -0800
commit0cb803d9ca4286601e9e6a3240cfa3488b662b7c (patch)
tree9c5000567bd52328ed9827c9e2e5a8c671d94158 /src/core/support/sync.c
parentbfc8a8d0496c1e505815772b623760a2ecf1e4d0 (diff)
Always ref writable streams
We suffered a bug whereby doing a follow-up write to another write could resurrect a deleted stream, causing all sorts of crash. Fix: when a stream becomes writable (vs when we start writing) take a ref on the stream, and only relinquish it once we're done writing.
Diffstat (limited to 'src/core/support/sync.c')
-rw-r--r--src/core/support/sync.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/core/support/sync.c b/src/core/support/sync.c
index d368422d9e..69e3e39c5c 100644
--- a/src/core/support/sync.c
+++ b/src/core/support/sync.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -98,6 +98,11 @@ void gpr_ref_init(gpr_refcount *r, int n) { gpr_atm_rel_store(&r->count, n); }
void gpr_ref(gpr_refcount *r) { gpr_atm_no_barrier_fetch_add(&r->count, 1); }
+void gpr_ref_non_zero(gpr_refcount *r) {
+ gpr_atm prior = gpr_atm_no_barrier_fetch_add(&r->count, 1);
+ GPR_ASSERT(prior > 0);
+}
+
void gpr_refn(gpr_refcount *r, int n) {
gpr_atm_no_barrier_fetch_add(&r->count, n);
}