ctdb-client: Drop TALLOC_CTX argument from ctdb_attach
authorAmitay Isaacs <amitay@gmail.com>
Tue, 17 Nov 2015 05:52:54 +0000 (16:52 +1100)
committerMartin Schwenke <martins@samba.org>
Wed, 24 Feb 2016 07:44:37 +0000 (08:44 +0100)
The database context returned is allocated off the client and is not
allocated from user-supplied TALLOC_CTX.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/client/client.h
ctdb/client/client_db.c

index ec077f7b4e8d899428dabb713a24fba4a4a53eff..aab21d501fa7475b85b558b6b0540d8c8693c56f 100644 (file)
@@ -718,7 +718,7 @@ struct tevent_req *ctdb_attach_send(TALLOC_CTX *mem_ctx,
 bool ctdb_attach_recv(struct tevent_req *req, int *perr,
                      struct ctdb_db_context **out);
 
-int ctdb_attach(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
+int ctdb_attach(struct tevent_context *ev,
                struct ctdb_client_context *client,
                struct timeval timeout,
                const char *db_name, uint8_t db_flags,
index bee148be61dce901be255a390ec0ee5709c6eacd..37e2ce51ec8c7b8118669d5e18f17d9ab6cb805b 100644 (file)
@@ -515,19 +515,26 @@ bool ctdb_attach_recv(struct tevent_req *req, int *perr,
        return true;
 }
 
-int ctdb_attach(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
+int ctdb_attach(struct tevent_context *ev,
                struct ctdb_client_context *client,
                struct timeval timeout,
                const char *db_name, uint8_t db_flags,
                struct ctdb_db_context **out)
 {
+       TALLOC_CTX *mem_ctx;
        struct tevent_req *req;
        bool status;
        int ret;
 
+       mem_ctx = talloc_new(client);
+       if (mem_ctx == NULL) {
+               return ENOMEM;
+       }
+
        req = ctdb_attach_send(mem_ctx, ev, client, timeout,
                               db_name, db_flags);
        if (req == NULL) {
+               talloc_free(mem_ctx);
                return ENOMEM;
        }
 
@@ -535,6 +542,7 @@ int ctdb_attach(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
 
        status = ctdb_attach_recv(req, &ret, out);
        if (! status) {
+               talloc_free(mem_ctx);
                return ret;
        }
 
@@ -544,6 +552,7 @@ int ctdb_attach(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
        ctdb_set_call(db, CTDB_FETCH_WITH_HEADER_FUNC, ctdb_fetch_with_header_func);
        */
 
+       talloc_free(mem_ctx);
        return 0;
 }