BUG/MINOR: peers: Missing calloc return value check in peers_register_table

A memory allocation failure happening during peers_register_table would
have resulted in a crash. This function is only called during init.

It was raised in GitHub issue #1233.
It could be backported to all stable branches.

(cherry picked from commit 208ff01b23eda19fe41780310f4d08ca86e28766)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit be5b1bb8cb683290f80856a3728ccaf3ad47b44b)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit cff2df91415d1b61700a77f62c8f7712b7fb7753)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 7dd75dbc1d7ef23aca3699098c61e63ab460a635)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/include/proto/peers.h b/include/proto/peers.h
index 74e20da..ec98711 100644
--- a/include/proto/peers.h
+++ b/include/proto/peers.h
@@ -56,7 +56,7 @@
 
 int peers_init_sync(struct peers *peers);
 int peers_alloc_dcache(struct peers *peers);
-void peers_register_table(struct peers *, struct stktable *table);
+int peers_register_table(struct peers *, struct stktable *table);
 void peers_setup_frontend(struct proxy *fe);
 
 #endif /* _PROTO_PEERS_H */
diff --git a/src/peers.c b/src/peers.c
index ad6a201..357491c 100644
--- a/src/peers.c
+++ b/src/peers.c
@@ -3139,16 +3139,21 @@
 
 /*
  * Function used to register a table for sync on a group of peers
- *
+ * Returns 0 in case of success.
  */
-void peers_register_table(struct peers *peers, struct stktable *table)
+int peers_register_table(struct peers *peers, struct stktable *table)
 {
 	struct shared_table *st;
 	struct peer * curpeer;
 	int id = 0;
+	int retval = 0;
 
 	for (curpeer = peers->remote; curpeer; curpeer = curpeer->next) {
 		st = calloc(1,sizeof(*st));
+		if (!st) {
+			retval = 1;
+			break;
+		}
 		st->table = table;
 		st->next = curpeer->tables;
 		if (curpeer->tables)
@@ -3166,6 +3171,8 @@
 	}
 
 	table->sync_task = peers->sync_task;
+
+	return retval;
 }
 
 /*
diff --git a/src/stick_table.c b/src/stick_table.c
index 689f149..72dcf22 100644
--- a/src/stick_table.c
+++ b/src/stick_table.c
@@ -630,6 +630,7 @@
 /* Perform minimal stick table intializations, report 0 in case of error, 1 if OK. */
 int stktable_init(struct stktable *t)
 {
+	int peers_retval = 0;
 	if (t->size) {
 		t->keys = EB_ROOT_UNIQUE;
 		memset(&t->exps, 0, sizeof(t->exps));
@@ -647,10 +648,10 @@
 			t->exp_task->context = (void *)t;
 		}
 		if (t->peers.p && t->peers.p->peers_fe && t->peers.p->peers_fe->state != PR_STSTOPPED) {
-			peers_register_table(t->peers.p, t);
+			peers_retval = peers_register_table(t->peers.p, t);
 		}
 
-		return t->pool != NULL;
+		return (t->pool != NULL) && !peers_retval;
 	}
 	return 1;
 }