summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/events.c33
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,