diff options
author | Volker Lendecke <vl@samba.org> | 2008-08-09 21:39:18 +0200 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2008-08-10 18:40:47 +0200 |
commit | 12ee6b832c7ff09010fc67122aaefcfce1cb712f (patch) | |
tree | 5db11f43fe7de497ecbb2ecaf7aaf0111e4ca26e /source3 | |
parent | 1a7b6fe34d6d7d29256fe3b5432593fa07d74838 (diff) | |
download | samba-12ee6b832c7ff09010fc67122aaefcfce1cb712f.tar.gz samba-12ee6b832c7ff09010fc67122aaefcfce1cb712f.tar.bz2 samba-12ee6b832c7ff09010fc67122aaefcfce1cb712f.zip |
Make events robust against their event_context being freed
(This used to be commit 3d4e7b29c235e329aaea4fa2c2078df0ce3e59eb)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/lib/events.c | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/source3/lib/events.c b/source3/lib/events.c index 7750176d8e..f03138708b 100644 --- a/source3/lib/events.c +++ b/source3/lib/events.c @@ -63,7 +63,9 @@ static int timed_event_destructor(struct timed_event *te) { DEBUG(10, ("Destroying timed event %lx \"%s\"\n", (unsigned long)te, te->event_name)); - DLIST_REMOVE(te->event_ctx->timed_events, te); + if (te->event_ctx != NULL) { + DLIST_REMOVE(te->event_ctx->timed_events, te); + } return 0; } @@ -131,9 +133,9 @@ struct timed_event *event_add_timed(struct event_context *event_ctx, static int fd_event_destructor(struct fd_event *fde) { - struct event_context *event_ctx = fde->event_ctx; - - DLIST_REMOVE(event_ctx->fd_events, fde); + if (fde->event_ctx != NULL) { + DLIST_REMOVE(fde->event_ctx->fd_events, fde); + } return 0; } @@ -354,9 +356,30 @@ int event_loop_once(struct event_context *ev) return 0; } +static int event_context_destructor(struct event_context *ev) +{ + while (ev->fd_events != NULL) { + ev->fd_events->event_ctx = NULL; + DLIST_REMOVE(ev->fd_events, ev->fd_events); + } + while (ev->timed_events != NULL) { + ev->timed_events->event_ctx = NULL; + DLIST_REMOVE(ev->timed_events, ev->timed_events); + } + return 0; +} + struct event_context *event_context_init(TALLOC_CTX *mem_ctx) { - return TALLOC_ZERO_P(mem_ctx, struct event_context); + struct event_context *result; + + result = TALLOC_ZERO_P(mem_ctx, struct event_context); + if (result == NULL) { + return NULL; + } + + talloc_set_destructor(result, event_context_destructor); + return result; } int set_event_dispatch_time(struct event_context *event_ctx, |