stats: Avoid NULL pointer deref in allocation failure paths.

We should either handle talloc returning NULL, or we should
OSMO_ASSERT().  Doing neither of the two is a bad idea.

Change-Id: I5e8d1cc22cf597f7f50c0f92bf86cb1f1413434c
diff --git a/src/stats.c b/src/stats.c
index 7b25ab1..16e6f62 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -214,7 +214,9 @@
 {
 	struct osmo_stats_reporter *srep;
 	srep = talloc_zero(osmo_stats_ctx, struct osmo_stats_reporter);
-	OSMO_ASSERT(srep);
+	if (!srep)
+		return NULL;
+
 	srep->type = type;
 	if (name)
 		srep->name = talloc_strdup(srep, name);
@@ -486,6 +488,8 @@
 	}
 
 	srep->buffer = msgb_alloc(buffer_size, "stats buffer");
+	if (!srep->buffer)
+		goto failed;
 
 	return 0;
 
@@ -569,6 +573,8 @@
 {
 	struct osmo_stats_reporter *srep;
 	srep = osmo_stats_reporter_alloc(OSMO_STATS_REPORTER_LOG, name);
+	if (!srep)
+		return NULL;
 
 	srep->have_net_config = 0;
 
diff --git a/src/stats_statsd.c b/src/stats_statsd.c
index b89ec92..b27baff 100644
--- a/src/stats_statsd.c
+++ b/src/stats_statsd.c
@@ -54,6 +54,8 @@
 {
 	struct osmo_stats_reporter *srep;
 	srep = osmo_stats_reporter_alloc(OSMO_STATS_REPORTER_STATSD, name);
+	if (!srep)
+		return NULL;
 
 	srep->have_net_config = 1;