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, 28 Dec 2012 11:58:38 +0000 (12:58 +0100)
Add a common exit point for cleanup.

Signed-off-by: Michael Adam <obnox@samba.org>
server/ctdb_vacuum.c

index c22f3e6a37c2fc03319808804688e477f76cd9f9..64e86622e4e879f6f4ee2fe5daeee5959baaab60 100644 (file)
@@ -710,7 +710,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;
 
@@ -735,7 +736,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,
@@ -758,7 +760,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;
                }
 
                /*
@@ -791,7 +794,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);
@@ -816,9 +820,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
@@ -850,7 +851,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;
 }
 
 /**