common/messaging: Free message list header if all message handlers are freed
authorAmitay Isaacs <amitay@gmail.com>
Tue, 2 Apr 2013 01:08:39 +0000 (12:08 +1100)
committerAmitay Isaacs <amitay@gmail.com>
Fri, 5 Apr 2013 04:19:43 +0000 (15:19 +1100)
This makes sure that even if the srvids are not deregistered, the header
structure is freed when the last message handler has been freed as a result of
client going away.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
(cherry picked from commit 4e1ec7412866f2d31c41de1bec0fbf788c03051b)

common/ctdb_message.c

index c6506f445ee183b157144718206d7d9eca4aecb2..86f1ff9350d361154fd226e8760e57a118eccce4 100644 (file)
@@ -177,6 +177,9 @@ static int message_handler_destructor(struct ctdb_message_list *m)
        struct ctdb_message_list_header *h = m->h;
 
        DLIST_REMOVE(h->m, m);
+       if (h->m == NULL) {
+               talloc_free(h);
+       }
        return 0;
 }
 
@@ -256,9 +259,6 @@ int ctdb_deregister_message_handler(struct ctdb_context *ctdb, uint64_t srvid, v
        for (m=h->m; m; m=m->next) {
                if (m->message_private == private_data) {
                        talloc_free(m);
-                       if (h->m == NULL) {
-                               talloc_free(h);
-                       }
                        return 0;
                }
        }