locking: Set destructor when lock_context is created
authorAmitay Isaacs <amitay@gmail.com>
Mon, 1 Jun 2015 14:22:07 +0000 (00:22 +1000)
committerAmitay Isaacs <amitay@gmail.com>
Mon, 15 Jun 2015 02:13:01 +0000 (12:13 +1000)
There is already code in the destructor to correctly remove it from the
pending or the active queue.  This also ensures that when lock context
is in pending queue and if the lock request gets freed, the lock context
is correctly removed from the pending queue.

Thanks to Stefan Metzmacher for noticing this and suggesting the fix.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=11293

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
(Imported from commit 5ae6a8f2fff5b5f4d46f496fd83f555be4b3d448)

server/ctdb_lock.c

index f5b5743eccbee29bda496972ee9d0f37fefceba5..bcd899c3bb1310f8566d68e14cd9126e17865c2a 100644 (file)
@@ -827,8 +827,6 @@ static void ctdb_lock_schedule(struct ctdb_context *ctdb)
        /* Parent process */
        close(lock_ctx->fd[1]);
 
-       talloc_set_destructor(lock_ctx, ctdb_lock_context_destructor);
-
        talloc_free(tmp_ctx);
 
        /* Set up timeout handler */
@@ -840,7 +838,6 @@ static void ctdb_lock_schedule(struct ctdb_context *ctdb)
        if (lock_ctx->ttimer == NULL) {
                ctdb_kill(ctdb, lock_ctx->child, SIGKILL);
                lock_ctx->child = -1;
-               talloc_set_destructor(lock_ctx, NULL);
                close(lock_ctx->fd[0]);
                return;
        }
@@ -856,7 +853,6 @@ static void ctdb_lock_schedule(struct ctdb_context *ctdb)
                TALLOC_FREE(lock_ctx->ttimer);
                ctdb_kill(ctdb, lock_ctx->child, SIGKILL);
                lock_ctx->child = -1;
-               talloc_set_destructor(lock_ctx, NULL);
                close(lock_ctx->fd[0]);
                return;
        }
@@ -954,6 +950,7 @@ static struct lock_request *ctdb_lock_internal(TALLOC_CTX *mem_ctx,
        request->private_data = private_data;
 
        talloc_set_destructor(request, ctdb_lock_request_destructor);
+       talloc_set_destructor(lock_ctx, ctdb_lock_context_destructor);
 
        ctdb_lock_schedule(ctdb);