vacuum: add explicit temporary memory context to ctdb_process_delete_list()
authorMichael Adam <obnox@samba.org>
Sat, 29 Dec 2012 16:16:33 +0000 (17:16 +0100)
committerMichael Adam <obnox@samba.org>
Fri, 26 Apr 2013 14:18:11 +0000 (16:18 +0200)
This removes the implicit artificial talloc hierarchy and makes the
code easier to understand.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-By: Amitay Isaacs <amitay@gmail.com>
(cherry picked from commit b7c3b8cdf92c597e621e3dae28b110d321de5ea8)

server/ctdb_vacuum.c

index c39dfaaf2d4cfb2e576d26bc996d9cc853a694eb..dc1afc3afb0ae57ee67e4580963bd1f48e51cb40 100644 (file)
@@ -708,17 +708,25 @@ static int ctdb_process_delete_list(struct ctdb_db_context *ctdb_db,
        struct ctdb_node_map *nodemap;
        uint32_t *active_nodes;
        int num_active_nodes;
+       TALLOC_CTX *tmp_ctx;
 
        if (vdata->delete_count == 0) {
                return 0;
        }
 
+       tmp_ctx = talloc_new(vdata);
+       if (tmp_ctx == NULL) {
+               DEBUG(DEBUG_ERR,(__location__ " Out of memory\n"));
+               return 0;
+       }
+
        vdata->delete_left = vdata->delete_count;
 
-       recs = talloc_zero(vdata, struct delete_records_list);
+       recs = talloc_zero(tmp_ctx, struct delete_records_list);
        if (recs == NULL) {
                DEBUG(DEBUG_ERR,(__location__ " Out of memory\n"));
-               return -1;
+               ret = -1;
+               goto done;
        }
        recs->records = (struct ctdb_marshall_buffer *)
                talloc_zero_size(recs,
@@ -747,7 +755,7 @@ static int ctdb_process_delete_list(struct ctdb_db_context *ctdb_db,
 
        ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(),
                                   CTDB_CURRENT_NODE,
-                                  recs, /* talloc context */
+                                  tmp_ctx,
                                   &nodemap);
        if (ret != 0) {
                DEBUG(DEBUG_ERR,(__location__ " unable to get node map\n"));
@@ -869,8 +877,7 @@ static int ctdb_process_delete_list(struct ctdb_db_context *ctdb_db,
        ret = 0;
 
 done:
-       /* free recs / nodemap / active_nodes */
-       talloc_free(recs);
+       talloc_free(tmp_ctx);
 
        return ret;
 }