diff options
author | Stefan Metzmacher <metze@samba.org> | 2009-01-05 19:23:23 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2009-01-05 22:44:54 +0100 |
commit | b09718fef22ba6805482e85fd0b0e339f19d2324 (patch) | |
tree | 5e4db863caf55b96164f86b56ca6d5d53c4d11ac /lib | |
parent | e240ca5bdd7e344ecce127997b67ca0a521e3ed8 (diff) | |
download | samba-b09718fef22ba6805482e85fd0b0e339f19d2324.tar.gz samba-b09718fef22ba6805482e85fd0b0e339f19d2324.tar.bz2 samba-b09718fef22ba6805482e85fd0b0e339f19d2324.zip |
tevent: add tevent_context destructor that unlinks the events from the context
metze
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tevent/tevent.c | 31 | ||||
-rw-r--r-- | lib/tevent/tevent_internal.h | 2 |
2 files changed, 33 insertions, 0 deletions
diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c index 5582b583e7..2e5abbff31 100644 --- a/lib/tevent/tevent.c +++ b/lib/tevent/tevent.c @@ -136,6 +136,35 @@ const char **tevent_backend_list(TALLOC_CTX *mem_ctx) return list; } +int tevent_common_context_destructor(struct tevent_context *ev) +{ + struct tevent_fd *fd; + struct tevent_timer *te; + struct tevent_signal *se; + + if (ev->pipe_fde) { + talloc_free(ev->pipe_fde); + ev->pipe_fde = NULL; + } + + for (fd=ev->fd_events; fd; fd = fd->next) { + fd->event_ctx = NULL; + DLIST_REMOVE(ev->fd_events, fd); + } + + for (te=ev->timer_events; te; te = te->next) { + te->event_ctx = NULL; + DLIST_REMOVE(ev->timer_events, te); + } + + for (se=ev->signal_events; se; se = se->next) { + se->event_ctx = NULL; + DLIST_REMOVE(ev->signal_events, se); + } + + return 0; +} + /* create a event_context structure for a specific implemementation. This must be the first events call, and all subsequent calls pass @@ -156,6 +185,8 @@ static struct tevent_context *tevent_context_init_ops(TALLOC_CTX *mem_ctx, ev = talloc_zero(mem_ctx, struct tevent_context); if (!ev) return NULL; + talloc_set_destructor(ev, tevent_common_context_destructor); + ev->ops = ops; ret = ev->ops->context_init(ev); diff --git a/lib/tevent/tevent_internal.h b/lib/tevent/tevent_internal.h index f58bb90816..32be12c8d8 100644 --- a/lib/tevent/tevent_internal.h +++ b/lib/tevent/tevent_internal.h @@ -152,6 +152,8 @@ struct tevent_context { bool tevent_register_backend(const char *name, const struct tevent_ops *ops); +int tevent_common_context_destructor(struct tevent_context *ev); + int tevent_common_fd_destructor(struct tevent_fd *fde); struct tevent_fd *tevent_common_add_fd(struct tevent_context *ev, TALLOC_CTX *mem_ctx, |