summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/events.c18
-rw-r--r--source4/lib/messaging/messaging.c15
2 files changed, 20 insertions, 13 deletions
diff --git a/source4/lib/events.c b/source4/lib/events.c
index 6f0bdb4fdd..a484295d8b 100644
--- a/source4/lib/events.c
+++ b/source4/lib/events.c
@@ -157,7 +157,8 @@ static int event_fd_destructor(void *ptr)
add a fd based event
return NULL on failure (memory allocation error)
*/
-struct fd_event *event_add_fd(struct event_context *ev, struct fd_event *e0)
+struct fd_event *event_add_fd(struct event_context *ev, struct fd_event *e0,
+ TALLOC_CTX *mem_ctx)
{
struct fd_event *e = talloc(ev->events, struct fd_event);
if (!e) return NULL;
@@ -168,6 +169,9 @@ struct fd_event *event_add_fd(struct event_context *ev, struct fd_event *e0)
ev->maxfd = e->fd;
}
talloc_set_destructor(e, event_fd_destructor);
+ if (mem_ctx) {
+ talloc_steal(mem_ctx, e);
+ }
return e;
}
@@ -226,7 +230,8 @@ static int event_timed_destructor(void *ptr)
add a timed event
return NULL on failure (memory allocation error)
*/
-struct timed_event *event_add_timed(struct event_context *ev, struct timed_event *e0)
+struct timed_event *event_add_timed(struct event_context *ev, struct timed_event *e0,
+ TALLOC_CTX *mem_ctx)
{
struct timed_event *e = talloc(ev->events, struct timed_event);
if (!e) return NULL;
@@ -234,6 +239,9 @@ struct timed_event *event_add_timed(struct event_context *ev, struct timed_event
e->event_ctx = ev;
DLIST_ADD(ev->timed_events, e);
talloc_set_destructor(e, event_timed_destructor);
+ if (mem_ctx) {
+ talloc_steal(mem_ctx, e);
+ }
return e;
}
@@ -259,7 +267,8 @@ static int event_loop_destructor(void *ptr)
add a loop event
return NULL on failure (memory allocation error)
*/
-struct loop_event *event_add_loop(struct event_context *ev, struct loop_event *e0)
+struct loop_event *event_add_loop(struct event_context *ev, struct loop_event *e0,
+ TALLOC_CTX *mem_ctx)
{
struct loop_event *e = talloc(ev->events, struct loop_event);
if (!e) return NULL;
@@ -267,6 +276,9 @@ struct loop_event *event_add_loop(struct event_context *ev, struct loop_event *e
e->event_ctx = ev;
DLIST_ADD(ev->loop_events, e);
talloc_set_destructor(e, event_loop_destructor);
+ if (mem_ctx) {
+ talloc_steal(mem_ctx, e);
+ }
return e;
}
diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c
index beceb342c9..ca7682f5d2 100644
--- a/source4/lib/messaging/messaging.c
+++ b/source4/lib/messaging/messaging.c
@@ -220,9 +220,7 @@ static void messaging_listen_handler(struct event_context *ev, struct fd_event *
fde2.flags = EVENT_FD_READ;
fde2.handler = messaging_recv_handler;
- rec->fde = event_add_fd(msg->event.ev, &fde2);
-
- talloc_steal(rec, rec->fde);
+ rec->fde = event_add_fd(msg->event.ev, &fde2, rec);
}
/*
@@ -358,8 +356,7 @@ static void messaging_backoff_handler(struct event_context *ev, struct timed_eve
fde.flags = EVENT_FD_WRITE;
fde.handler = messaging_send_handler;
- rec->fde = event_add_fd(msg->event.ev, &fde);
- talloc_steal(rec, rec->fde);
+ rec->fde = event_add_fd(msg->event.ev, &fde, rec);
messaging_send_handler(msg->event.ev, rec->fde, timeval_zero(), EVENT_FD_WRITE);
}
@@ -408,7 +405,7 @@ NTSTATUS messaging_send(struct messaging_context *msg, servid_t server, uint32_t
te.next_event = timeval_current_ofs(0, MESSAGING_BACKOFF);
te.handler = messaging_backoff_handler;
te.private = rec;
- event_add_timed(msg->event.ev, &te);
+ event_add_timed(msg->event.ev, &te, rec);
return NT_STATUS_OK;
}
@@ -422,8 +419,7 @@ NTSTATUS messaging_send(struct messaging_context *msg, servid_t server, uint32_t
fde.flags = EVENT_FD_WRITE;
fde.handler = messaging_send_handler;
- rec->fde = event_add_fd(msg->event.ev, &fde);
- talloc_steal(rec, rec->fde);
+ rec->fde = event_add_fd(msg->event.ev, &fde, rec);
messaging_send_handler(msg->event.ev, rec->fde, timeval_zero(), EVENT_FD_WRITE);
@@ -501,8 +497,7 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, servid_t server_id
fde.handler = messaging_listen_handler;
msg->event.ev = talloc_reference(msg,ev);
- msg->event.fde = event_add_fd(ev, &fde);
- talloc_steal(msg, msg->event.fde);
+ msg->event.fde = event_add_fd(ev, &fde, msg);
talloc_set_destructor(msg, messaging_destructor);