From 573e4e2d2bd09dd9579150cce926de774a0b609c Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Wed, 2 Jun 2010 13:49:34 +1000 Subject: [PATCH] Make the call to free the request explicit in the callback instead of implicit --- include/ctdb.h | 7 ++++--- libctdb/ctdb.c | 2 +- libctdb/tst.c | 3 +++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/ctdb.h b/include/ctdb.h index 040cd0c2..32a7a2c3 100644 --- a/include/ctdb.h +++ b/include/ctdb.h @@ -26,13 +26,13 @@ #include /* All *_send() functions are guaranteed to be non-blocking and fully - * asynchronous. The non-_send variants are synchronous. */ + * asynchronous. The non-_send variants are synchronous. + */ /* * Connect to ctdb using the specified domain socket. * Returns a ctdb context if successful or NULL. * - * Use ctdb_free() to release the returned ctdb_connection when finished. */ struct ctdb_connection *ctdb_connect(const char *addr); @@ -48,7 +48,8 @@ void ctdb_request_free(struct ctdb_request *req); /* * Callback for completed requests: it would normally unpack the request - * using ctdb_*_recv(). You must free the request using ctdb_request_free(). + * using ctdb_*_recv(). + * You must free the request using ctdb_request_free(). * * Note that due to macro magic, your callback doesn't have to take void *, * it can take a type which matches the actual private parameter. diff --git a/libctdb/ctdb.c b/libctdb/ctdb.c index 08355efb..e49e3d8c 100644 --- a/libctdb/ctdb.c +++ b/libctdb/ctdb.c @@ -75,6 +75,7 @@ static void set_pnn(struct ctdb_connection *ctdb, /* FIXME: Report error. */ ctdb->broken = true; } + ctdb_request_free(req); } struct ctdb_connection *ctdb_connect(const char *addr) @@ -240,7 +241,6 @@ static void handle_incoming(struct ctdb_connection *ctdb, struct io_elem *in) DLIST_REMOVE(ctdb->doneq, i); i->reply = in; i->callback(ctdb, i, i->priv_data); - ctdb_request_free(i); return; } } diff --git a/libctdb/tst.c b/libctdb/tst.c index af23a569..6fd376a7 100644 --- a/libctdb/tst.c +++ b/libctdb/tst.c @@ -50,6 +50,7 @@ static void pnn_cb(struct ctdb_connection *ctdb, uint32_t pnn; status = ctdb_getpnn_recv(req, &pnn); + ctdb_request_free(req); if (status != 0) { printf("Error reading PNN\n"); return; @@ -64,6 +65,7 @@ static void rm_cb(struct ctdb_connection *ctdb, uint32_t rm; status = ctdb_getrecmaster_recv(req, &rm); + ctdb_request_free(req); if (status != 0) { printf("Error reading RECMASTER\n"); return; @@ -118,6 +120,7 @@ void message_handler_cb(struct ctdb_connection *ctdb, if (ctdb_set_message_handler_recv(ctdb, req) != 0) { err(1, "registering message"); } + ctdb_request_free(req); printf("Message handler registered\n"); registered = true; } -- 2.34.1