From ead5a3111f3b3e0639b1dc7725a7c233f1ee9cae Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Mon, 8 Jul 2024 17:57:27 +1000 Subject: [PATCH] ctdb-daemon: Use ctdb_parse_node_address() in ctdbd While here, fix a trivial memory leak (ctdbd will exit anyway if this function fails). Signed-off-by: Martin Schwenke Reviewed-by: Anoop C S Autobuild-User(master): Martin Schwenke Autobuild-Date(master): Tue Jul 23 12:39:18 UTC 2024 on atb-devel-224 --- ctdb/common/common.h | 3 --- ctdb/common/ctdb_util.c | 30 ------------------------------ ctdb/server/ctdb_server.c | 6 +++++- 3 files changed, 5 insertions(+), 34 deletions(-) diff --git a/ctdb/common/common.h b/ctdb/common/common.h index 6a52fb4e4c6..1f6f937663c 100644 --- a/ctdb/common/common.h +++ b/ctdb/common/common.h @@ -101,9 +101,6 @@ bool ctdb_set_helper(const char *type, char *helper, size_t size, const char *envvar, const char *dir, const char *file); -int ctdb_parse_address(TALLOC_CTX *mem_ctx, const char *str, - ctdb_sock_addr *address); - bool ctdb_same_address(ctdb_sock_addr *a1, ctdb_sock_addr *a2); uint32_t ctdb_hash(const TDB_DATA *key); diff --git a/ctdb/common/ctdb_util.c b/ctdb/common/ctdb_util.c index 831a2877b8a..0b4876725a0 100644 --- a/ctdb/common/ctdb_util.c +++ b/ctdb/common/ctdb_util.c @@ -140,36 +140,6 @@ bool ctdb_set_helper(const char *type, char *helper, size_t size, return true; } -/* - parse a IP:port pair -*/ -int ctdb_parse_address(TALLOC_CTX *mem_ctx, const char *str, - ctdb_sock_addr *address) -{ - struct servent *se; - int port; - int ret; - - setservent(0); - se = getservbyname("ctdb", "tcp"); - endservent(); - - if (se == NULL) { - port = CTDB_PORT; - } else { - port = ntohs(se->s_port); - } - - ret = ctdb_sock_addr_from_string(str, address, false); - if (ret != 0) { - return -1; - } - ctdb_sock_addr_set_port(address, port); - - return 0; -} - - /* check if two addresses are the same */ diff --git a/ctdb/server/ctdb_server.c b/ctdb/server/ctdb_server.c index 40f8e289239..b7a33af7ecf 100644 --- a/ctdb/server/ctdb_server.c +++ b/ctdb/server/ctdb_server.c @@ -154,10 +154,14 @@ fail: */ int ctdb_set_address(struct ctdb_context *ctdb, const char *address) { + bool ok; + ctdb->address = talloc(ctdb, ctdb_sock_addr); CTDB_NO_MEMORY(ctdb, ctdb->address); - if (ctdb_parse_address(ctdb, address, ctdb->address) != 0) { + ok = ctdb_parse_node_address(address, ctdb->address); + if (!ok) { + TALLOC_FREE(ctdb->address); return -1; }