# HG changeset patch # User Thinker K.F. Li # Date 1221552364 -28800 # Node ID d2cc7400c97187d28ccf04d5aa1613481e8ef053 # Parent 55f2c6402c81e4b8d862ad7ffdec78f03008ce62 Bug of subject_notify() when free subjects. diff -r 55f2c6402c81 -r d2cc7400c971 src/observer.c --- a/src/observer.c Tue Sep 16 15:44:01 2008 +0800 +++ b/src/observer.c Tue Sep 16 16:06:04 2008 +0800 @@ -48,15 +48,15 @@ void subject_notify(ob_factory_t *factory, subject_t *subject, event_t *evt) { observer_t *observer; - /*! - * \note What is happend when the subject is freed by observer? - * Postponding the request of free until notification - * been finished. (\ref SUBF_BUSY / \ref SUBF_FREE) - */ - subject->flags |= SUBF_BUSY; - evt->tgt = subject; while(subject) { + /*! + * \note What is happend when the subject is freed by observer? + * Postponding the request of free until notification + * been finished. (\ref SUBF_BUSY / \ref SUBF_FREE) + */ + subject->flags |= SUBF_BUSY; + evt->cur_tgt = subject->obj; for(observer = STAILQ_HEAD(subject->observers); observer != NULL; @@ -64,15 +64,16 @@ observer->hdr(evt, observer->arg); } + subject->flags &= ~SUBF_BUSY; + if(subject->flags & SUBF_FREE) + subject_free(factory, subject); + if(subject->flags & SUBF_STOP_PROPAGATE) break; subject = factory->get_parent_subject(factory, subject); } - subject->flags &= ~SUBF_BUSY; - if(subject->flags & SUBF_FREE) - subject_free(factory, subject); } observer_t *subject_add_observer(ob_factory_t *factory,