ctdb-recoverd: Use talloc() to allocate recovery lock handle
authorMartin Schwenke <martin@meltin.net>
Mon, 3 Sep 2018 01:43:44 +0000 (11:43 +1000)
committerMartin Schwenke <martins@samba.org>
Mon, 17 Sep 2018 20:58:20 +0000 (22:58 +0200)
At the moment this is still local and is freed after the mutex is
successfully taken.

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

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

index c61fec7cce87edabdfa902490700afd6c71d7829..4655dcc496af1e1fe99dbdbf06bb26394e757ccf 100644 (file)
@@ -932,31 +932,43 @@ static bool ctdb_recovery_lock(struct ctdb_recoverd *rec)
 {
        struct ctdb_context *ctdb = rec->ctdb;
        struct ctdb_cluster_mutex_handle *h;
-       struct ctdb_recovery_lock_handle s = {
-               .done = false,
-               .locked = false,
-               .latency = 0,
+       struct ctdb_recovery_lock_handle *s;
+
+       s = talloc_zero(rec, struct ctdb_recovery_lock_handle);
+       if (s == NULL) {
+               DBG_ERR("Memory allocation error\n");
+               return false;
        };
 
-       h = ctdb_cluster_mutex(rec, ctdb, ctdb->recovery_lock, 0,
-                              take_reclock_handler, &s,
-                              lost_reclock_handler, rec);
+       h = ctdb_cluster_mutex(rec,
+                              ctdb,
+                              ctdb->recovery_lock,
+                              0,
+                              take_reclock_handler,
+                              s,
+                              lost_reclock_handler,
+                              rec);
        if (h == NULL) {
+               talloc_free(s);
                return false;
        }
 
-       while (!s.done) {
+       while (! s->done) {
                tevent_loop_once(ctdb->ev);
        }
 
-       if (! s.locked) {
+       if (! s->locked) {
+               talloc_free(s);
                talloc_free(h);
                return false;
        }
 
        rec->recovery_lock_handle = h;
-       ctdb_ctrl_report_recd_lock_latency(ctdb, CONTROL_TIMEOUT(),
-                                          s.latency);
+       ctdb_ctrl_report_recd_lock_latency(ctdb,
+                                          CONTROL_TIMEOUT(),
+                                          s->latency);
+
+       talloc_free(s);
 
        return true;
 }