s4: messaging: When talloc_free()'ing an event context, only remove msg_dgm_ref's...
[bbaumbach/samba-autobuild/.git] / source4 / lib / messaging / messaging.c
index 19873c5bc39dfb99c3be63c834456e6a5868d213..2da0acc0c7ab021f00e3dc9212103c3992defd4b 100644 (file)
@@ -256,18 +256,20 @@ static int imessaging_context_destructor(struct imessaging_context *msg)
 }
 
 /*
- * Cleanup messaging dgm contexts
+ * Cleanup messaging dgm contexts on a specific event context.
  *
  * We must make sure to unref all messaging_dgm_ref's *before* the
  * tevent context goes away. Only when the last ref is freed, the
  * refcounted messaging dgm context will be freed.
  */
-void imessaging_dgm_unref_all(void)
+void imessaging_dgm_unref_ev(struct tevent_context *ev)
 {
        struct imessaging_context *msg = NULL;
 
        for (msg = msg_ctxs; msg != NULL; msg = msg->next) {
-               TALLOC_FREE(msg->msg_dgm_ref);
+               if (msg->ev == ev) {
+                       TALLOC_FREE(msg->msg_dgm_ref);
+               }
        }
 }