tevent: add tevent_context destructor that unlinks the events from the context
authorStefan Metzmacher <metze@samba.org>
Mon, 5 Jan 2009 18:23:23 +0000 (19:23 +0100)
committerStefan Metzmacher <metze@samba.org>
Mon, 5 Jan 2009 21:44:54 +0000 (22:44 +0100)
metze

lib/tevent/tevent.c
lib/tevent/tevent_internal.h

index 5582b583e7304c06867033dea97f1acdba00f7ae..2e5abbff312295c2b0e493d25480379822d78e73 100644 (file)
@@ -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);
index f58bb90816f9ed9ca8cb033c7db7a3f6ad3c9fe2..32be12c8d882307e1a04c9d0e6ecca7476945635 100644 (file)
@@ -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,