vacuum: free temporary allocated memory correctly in ctdb_process_delete_list().
authorMichael Adam <obnox@samba.org>
Mon, 17 Dec 2012 16:31:55 +0000 (17:31 +0100)
committerMichael Adam <obnox@samba.org>
Fri, 26 Apr 2013 14:17:49 +0000 (16:17 +0200)
Add a common exit point for cleanup.

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

server/ctdb_vacuum.c

index bf82d58c8d2e2d8d7594c726088fd12c2bc00df8..07595e9029577c1741510f2f1b5f711306442b44 100644 (file)
@@ -725,7 +725,8 @@ static int ctdb_process_delete_list(struct ctdb_db_context *ctdb_db,
                            offsetof(struct ctdb_marshall_buffer, data));
        if (recs->records == NULL) {
                DEBUG(DEBUG_ERR,(__location__ " Out of memory\n"));
-               return -1;
+               ret = -1;
+               goto done;
        }
        recs->records->db_id = ctdb_db->db_id;
 
@@ -750,7 +751,8 @@ static int ctdb_process_delete_list(struct ctdb_db_context *ctdb_db,
                                   &nodemap);
        if (ret != 0) {
                DEBUG(DEBUG_ERR,(__location__ " unable to get node map\n"));
-               return -1;
+               ret = -1;
+               goto done;
        }
 
        active_nodes = list_of_active_nodes(ctdb, nodemap,
@@ -773,7 +775,8 @@ static int ctdb_process_delete_list(struct ctdb_db_context *ctdb_db,
                        DEBUG(DEBUG_ERR, ("Failed to delete records on "
                                          "node %u: ret[%d] res[%d]\n",
                                          active_nodes[i], ret, res));
-                       return -1;
+                       ret = -1;
+                       goto done;
                }
 
                /*
@@ -806,7 +809,8 @@ static int ctdb_process_delete_list(struct ctdb_db_context *ctdb_db,
 
                        if (recdata.dsize < sizeof(struct ctdb_ltdb_header)) {
                                DEBUG(DEBUG_CRIT,(__location__ " bad ltdb record\n"));
-                               return -1;
+                               ret = -1;
+                               goto done;
                        }
                        rechdr = (struct ctdb_ltdb_header *)recdata.dptr;
                        recdata.dptr += sizeof(*rechdr);
@@ -831,9 +835,6 @@ static int ctdb_process_delete_list(struct ctdb_db_context *ctdb_db,
                }
        }
 
-       /* free nodemap and active_nodes */
-       talloc_free(nodemap);
-
        if (vdata->delete_left > 0) {
                /*
                 * The only records remaining in the tree are those
@@ -865,7 +866,13 @@ static int ctdb_process_delete_list(struct ctdb_db_context *ctdb_db,
                       (unsigned)vdata->delete_left));
        }
 
-       return 0;
+       ret = 0;
+
+done:
+       /* free recs / nodemap / active_nodes */
+       talloc_free(recs);
+
+       return ret;
 }
 
 /**