libctdb: check ctdb_request_free & ctdb_cancel used appropriately.
authorRusty Russell <rusty@rustcorp.com.au>
Fri, 18 Jun 2010 05:45:11 +0000 (15:15 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Fri, 18 Jun 2010 05:45:11 +0000 (15:15 +0930)
Since I made this mistake myself, we should check for it.

We could have one function that does both, but from a user's point of
view they are very different and it's quite possibly a bug if they
think the request is finished/unfinished when it's not.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
libctdb/ctdb.c

index 527cb7891b1359b091e6670e60f36e04d464c4e3..1c16d36a7c18e2acbbcd3059014dbca3ab9413b2 100644 (file)
@@ -201,6 +201,13 @@ struct ctdb_request *new_ctdb_request(size_t len,
 
 void ctdb_request_free(struct ctdb_connection *ctdb, struct ctdb_request *req)
 {
+       if (req->next || req->prev) {
+               DEBUG(ctdb, LOG_ALERT,
+                     "ctdb_request_free: request not complete! ctdb_cancel? %p (id %u)",
+                     req, req->hdr.hdr ? req->hdr.hdr->reqid : 0);
+               ctdb_cancel(ctdb, req);
+               return;
+       }
        if (req->extra_destructor) {
                req->extra_destructor(ctdb, req);
        }
@@ -456,6 +463,14 @@ void ctdb_cancel_callback(struct ctdb_connection *ctdb,
 
 void ctdb_cancel(struct ctdb_connection *ctdb, struct ctdb_request *req)
 {
+       if (!req->next && !req->prev) {
+               DEBUG(ctdb, LOG_ALERT,
+                     "ctdb_cancel: request completed! ctdb_request_free? %p (id %u)",
+                     req, req->hdr.hdr ? req->hdr.hdr->reqid : 0);
+               ctdb_request_free(ctdb, req);
+               return;
+       }
+
        DEBUG(ctdb, LOG_DEBUG, "ctdb_cancel: %p (id %u)",
              req, req->hdr.hdr ? req->hdr.hdr->reqid : 0);