From 826c37e1c6c30ceed337072dbcdb123d95c3baf2 Mon Sep 17 00:00:00 2001 From: Guo Rui Date: Wed, 22 Jul 2009 00:25:41 +0800 Subject: [PATCH] Clear invalid reference in get_broker_obj(). --- src/script.c | 7 ++++++- src/script.h | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/script.c b/src/script.c index c0473f7..87aefe1 100644 --- a/src/script.c +++ b/src/script.c @@ -366,14 +366,17 @@ get_obj_broker(void *obj) return *bucket; } -void * get_broker_obj(struct broker *broker) +void * get_broker_obj(struct broker **pbroker) { + struct broker *broker = *pbroker; if (!broker) return NULL; if (broker->valid) return broker->obj; + /* Clear the invalid reference, and decrease the ref-count. */ + *pbroker = NULL; if (--broker->ref == 0) { struct broker *n, **b = broker_from_obj(broker->obj); @@ -381,6 +384,8 @@ void * get_broker_obj(struct broker *broker) n = (*b)->b_next; free(*b); *b = n; + } else { + /* Should not happen!*/ } } return NULL; diff --git a/src/script.h b/src/script.h index dda07ac..5f9a1e4 100644 --- a/src/script.h +++ b/src/script.h @@ -87,11 +87,11 @@ struct broker * A counter is maintained for broker references. A broker to valid object can * be dereferenced as many times as you wish. But once the object is * invalidated, each dereference action will decrease the counter by one, and - * return a NULL pointer. The binding should further invalidate the script - * variable that refers to the broker. This scheme will work for languages + * return a NULL pointer. The invalid reference will be cleared in such a + * situation. This scheme will work for languages * that always treat host objects as reference and never do value copy.*/ struct broker *get_obj_broker(void *obj); -void * get_broker_obj(struct broker *broker); +void * get_broker_obj(struct broker **pbroker); void broker_inv_obj(void *obj); struct gevents -- 2.11.4.GIT