s4: messaging: When talloc_free()'ing an event context, only remove msg_dgm_ref's...
authorJeremy Allison <jra@samba.org>
Mon, 3 Apr 2017 17:58:24 +0000 (17:58 +0000)
committerJeremy Allison <jra@samba.org>
Mon, 17 Apr 2017 17:13:07 +0000 (19:13 +0200)
Defensive programming change. Not strictly needed to prevent
any crash/error.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
source4/lib/messaging/messaging.c
source4/lib/messaging/messaging.h
source4/smbd/server.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);
+               }
        }
 }
 
index e587fdfb3aa0847c1f685303ca796d49fb88e3db..668464dc061d9fe07a57c0b93308a25c708f7eb6 100644 (file)
@@ -44,7 +44,7 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
                                           struct loadparm_context *lp_ctx,
                                           struct server_id server_id,
                                           struct tevent_context *ev);
-void imessaging_dgm_unref_all(void);
+void imessaging_dgm_unref_ev(struct tevent_context *ev);
 NTSTATUS imessaging_reinit_all(void);
 int imessaging_cleanup(struct imessaging_context *msg);
 struct imessaging_context *imessaging_client_init(TALLOC_CTX *mem_ctx,
index 98148374e5bced23491d8da13966a3d00e6cfcf5..ec56d1025ea0de609f7fba95ea30099d2a5c92fe 100644 (file)
@@ -324,7 +324,7 @@ static void show_build(void)
 
 static int event_ctx_destructor(struct tevent_context *event_ctx)
 {
-       imessaging_dgm_unref_all();
+       imessaging_dgm_unref_ev(event_ctx);
        return 0;
 }