summaryrefslogtreecommitdiff
path: root/ctdb
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2018-01-18 16:31:39 +1100
committerAmitay Isaacs <amitay@samba.org>2020-08-18 05:02:25 +0000
commit2eaa0af6160588b6e3364b181d0976477d12b51b (patch)
tree0df1b551d672a5cd0db68c7b0bcd03cd07a2e526 /ctdb
parent3324dd272c7dafa92cd9c3fd0af8f50084bcdaaa (diff)
downloadsamba-2eaa0af6160588b6e3364b181d0976477d12b51b.tar.gz
ctdb-recoverd: Move memory allocation into get_remote_nodemaps()
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14466 Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb')
-rw-r--r--ctdb/server/ctdb_recoverd.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/ctdb/server/ctdb_recoverd.c b/ctdb/server/ctdb_recoverd.c
index b08950a17bc..c6254ae3404 100644
--- a/ctdb/server/ctdb_recoverd.c
+++ b/ctdb/server/ctdb_recoverd.c
@@ -2243,12 +2243,21 @@ static void async_getnodemap_callback(struct ctdb_context *ctdb,
static int get_remote_nodemaps(struct ctdb_recoverd *rec,
TALLOC_CTX *mem_ctx,
- struct ctdb_node_map_old **remote_nodemaps)
+ struct ctdb_node_map_old ***remote_nodemaps)
{
struct ctdb_context *ctdb = rec->ctdb;
+ struct ctdb_node_map_old **t;
uint32_t *nodes;
int ret;
+ t = talloc_zero_array(mem_ctx,
+ struct ctdb_node_map_old *,
+ rec->nodemap->num);
+ if (t == NULL) {
+ DBG_ERR("Memory allocation error\n");
+ return -1;
+ }
+
nodes = list_of_active_nodes(ctdb, rec->nodemap, mem_ctx, true);
ret = ctdb_client_async_control(ctdb,
@@ -2260,9 +2269,16 @@ static int get_remote_nodemaps(struct ctdb_recoverd *rec,
tdb_null,
async_getnodemap_callback,
NULL,
- remote_nodemaps);
+ t);
talloc_free(nodes);
- return ret;
+
+ if (ret != 0) {
+ talloc_free(t);
+ return ret;
+ }
+
+ *remote_nodemaps = t;
+ return 0;
}
static bool validate_recovery_master(struct ctdb_recoverd *rec,
@@ -2584,15 +2600,7 @@ static void main_loop(struct ctdb_context *ctdb, struct ctdb_recoverd *rec,
/* get the nodemap for all active remote nodes
*/
- remote_nodemaps = talloc_array(mem_ctx, struct ctdb_node_map_old *, nodemap->num);
- if (remote_nodemaps == NULL) {
- DEBUG(DEBUG_ERR, (__location__ " failed to allocate remote nodemap array\n"));
- return;
- }
- for(i=0; i<nodemap->num; i++) {
- remote_nodemaps[i] = NULL;
- }
- ret = get_remote_nodemaps(rec, mem_ctx, remote_nodemaps);
+ ret = get_remote_nodemaps(rec, mem_ctx, &remote_nodemaps);
if (ret != 0) {
DBG_ERR("Failed to read remote nodemaps\n");
return;