diff options
author | Craig Tiller <ctiller@google.com> | 2016-05-07 22:11:37 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2016-05-07 22:11:37 -0700 |
commit | 965eab3aa2eb56cfa5df068390c71d513b1655e3 (patch) | |
tree | 0622f9e8675755890ff0de0a46378cb6b4386ffd /src/core/lib | |
parent | 71d28ad3b50068a677254e01c514eb0f7290063c (diff) |
Fix refcounting
Diffstat (limited to 'src/core/lib')
-rw-r--r-- | src/core/lib/iomgr/error.c | 9 | ||||
-rw-r--r-- | src/core/lib/iomgr/error.h | 2 | ||||
-rw-r--r-- | src/core/lib/support/avl.c | 9 |
3 files changed, 17 insertions, 3 deletions
diff --git a/src/core/lib/iomgr/error.c b/src/core/lib/iomgr/error.c index d67eb6e425..6d16a54d57 100644 --- a/src/core/lib/iomgr/error.c +++ b/src/core/lib/iomgr/error.c @@ -240,8 +240,13 @@ grpc_error *grpc_error_set_int(grpc_error *src, grpc_error_ints which, return new; } -const intptr_t *grpc_error_get_int(grpc_error *err, grpc_error_ints which) { - return gpr_avl_get(err->ints, (void *)(uintptr_t)which); +bool grpc_error_get_int(grpc_error *err, grpc_error_ints which, intptr_t *p) { + void *pp; + if (gpr_avl_maybe_get(err->ints, (void *)(uintptr_t)which, &pp)) { + if (p != NULL) *p = (intptr_t)pp; + return true; + } + return false; } grpc_error *grpc_error_set_str(grpc_error *src, grpc_error_strs which, diff --git a/src/core/lib/iomgr/error.h b/src/core/lib/iomgr/error.h index 266a621704..2b9b9f00c0 100644 --- a/src/core/lib/iomgr/error.h +++ b/src/core/lib/iomgr/error.h @@ -107,7 +107,7 @@ void grpc_error_unref(grpc_error *err, const char *file, int line, grpc_error *grpc_error_set_int(grpc_error *src, grpc_error_ints which, intptr_t value); -const intptr_t *grpc_error_get_int(grpc_error *error, grpc_error_ints which); +bool grpc_error_get_int(grpc_error *error, grpc_error_ints which, intptr_t *p); grpc_error *grpc_error_set_time(grpc_error *src, grpc_error_times which, gpr_timespec value); grpc_error *grpc_error_set_str(grpc_error *src, grpc_error_strs which, diff --git a/src/core/lib/support/avl.c b/src/core/lib/support/avl.c index ceded9d266..acf8fd5a55 100644 --- a/src/core/lib/support/avl.c +++ b/src/core/lib/support/avl.c @@ -124,6 +124,15 @@ void *gpr_avl_get(gpr_avl avl, void *key) { return node ? node->value : NULL; } +int gpr_avl_maybe_get(gpr_avl avl, void *key, void **value) { + gpr_avl_node *node = get(avl.vtable, avl.root, key); + if (node != NULL) { + *value = node->value; + return 1; + } + return 0; +} + static gpr_avl_node *rotate_left(const gpr_avl_vtable *vtable, void *key, void *value, gpr_avl_node *left, gpr_avl_node *right) { |