autofs-5.1.9 - dont initialize hosts list in add_host()

From: Ian Kent <raven@themaw.net>

The add_host() function is called for cases where the hosts list is not
null and also where it might be NULL.

Make the different cases clear by moving the initialisation out of the
add_host() function so it isn't called with a NULL hosts list.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 CHANGELOG            |    1 +
 modules/replicated.c |   20 +++++++++++---------
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index c4853a930..01a7ffb2c 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -42,6 +42,7 @@
 - fix dont delay expire.
 - make mnts_has_mounted_mounts() check submounts.
 - fix string length check in merge_options()
+- dont initialize hosts list in add_host().
 
 02/11/2023 autofs-5.1.9
 - fix kernel mount status notification.
diff --git a/modules/replicated.c b/modules/replicated.c
index 5e2f8b17c..0c715ba73 100644
--- a/modules/replicated.c
+++ b/modules/replicated.c
@@ -130,11 +130,6 @@ static int add_host(struct host **list, struct host *host)
 {
 	struct host *this, *last;
 
-	if (!*list) {
-		*list = host;
-		return 1;
-	}
-
 	this = *list;
 	last = this;
 	while (this) {
@@ -961,9 +956,13 @@ static int add_new_host(struct host **list,
 	if (!new)
 		return 0;
 
-	if (!add_host(list, new)) {
-		free_host(new);
-		return 0;
+	if (!*list)
+		*list = new;
+	else {
+		if (!add_host(list, new)) {
+			free_host(new);
+			return 0;
+		}
 	}
 	new->rr = rr;
 
@@ -1104,7 +1103,10 @@ static int add_local_path(struct host **hosts, const char *path)
 	new->addr = NULL;
 	new->weight = new->cost = 0;
 
-	add_host(hosts, new);
+	if (!*hosts)
+		*hosts = new;
+	else
+		add_host(hosts, new);
 
 	return 1;
 }
