tevent: add tevent_threaded_schedule_immediate_destructor that just aborts
authorStefan Metzmacher <metze@samba.org>
Fri, 23 Mar 2018 09:32:15 +0000 (10:32 +0100)
committerRalph Boehme <slow@samba.org>
Wed, 11 Jul 2018 21:04:19 +0000 (23:04 +0200)
This will be active while the event is part of the ev->scheduled_immediates
list.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
lib/tevent/tevent_threads.c

index 3f91ab8bc2abf01957526f6dba204c2edb2bc092..efdac9856dd16016e129bab7a3d988d6cf579f24 100644 (file)
@@ -441,6 +441,14 @@ struct tevent_threaded_context *tevent_threaded_context_create(
 #endif
 }
 
+static int tevent_threaded_schedule_immediate_destructor(struct tevent_immediate *im)
+{
+       if (im->event_ctx != NULL) {
+               abort();
+       }
+       return 0;
+}
+
 void _tevent_threaded_schedule_immediate(struct tevent_threaded_context *tctx,
                                         struct tevent_immediate *im,
                                         tevent_immediate_handler_t handler,
@@ -484,6 +492,14 @@ void _tevent_threaded_schedule_immediate(struct tevent_threaded_context *tctx,
                .schedule_location      = location,
        };
 
+       /*
+        * Make sure the event won't be destroyed while
+        * it's part of the ev->scheduled_immediates list.
+        * _tevent_schedule_immediate() will reset the destructor
+        * in tevent_common_threaded_activate_immediate().
+        */
+       talloc_set_destructor(im, tevent_threaded_schedule_immediate_destructor);
+
        ret = pthread_mutex_lock(&ev->scheduled_mutex);
        if (ret != 0) {
                abort();