Commit fd10b993b091f2f9cbf34f5381330b93195f5071

Con Kolivas 2011-07-19T09:43:15

Move add pool to somewhere clean and obvious.

diff --git a/main.c b/main.c
index 61a4878..82d4f30 100644
--- a/main.c
+++ b/main.c
@@ -206,6 +206,17 @@ static void applog_and_exit(const char *fmt, ...)
 	exit(1);
 }
 
+static void add_pool(void)
+{
+	total_pools++;
+	pools = realloc(pools, sizeof(struct pool) * total_pools);
+	if (!pools) {
+		applog(LOG_ERR, "Failed to malloc pools in add_pool");
+		exit (1);
+	}
+	memset(&pools[total_pools - 1], 0, sizeof(struct pool));
+}
+
 /* FIXME: Use asprintf for better errors. */
 static char *set_algo(const char *arg, enum sha256_algos *algo)
 {
@@ -277,12 +288,8 @@ static char *set_url(const char *arg, char **p)
 {
 	struct pool *pool;
 
-	total_pools++;
-	pools = realloc(pools, sizeof(struct pool) * total_pools);
-	if (!pools)
-		return "Failed to malloc pools in set_url";
+	add_pool();
 	pool = &pools[total_pools - 1];
-	memset(pool, 0, sizeof(struct pool));
 
 	opt_set_charp(arg, &pool->rpc_url);
 	if (strncmp(arg, "http://", 7) &&