From ab08ef82307c04c055113515c1893bb741a2f517 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 15 Jun 2022 10:23:28 -0400 Subject: [PATCH 1/2] lib: stream_dup memory alloc cannot fail If stream_dup calls stream_new, stream_new can never return a NULL pointer so the check is unneeded. Signed-off-by: Donald Sharp --- lib/stream.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/stream.c b/lib/stream.c index c15baa0a2c..011e921c0d 100644 --- a/lib/stream.c +++ b/lib/stream.c @@ -145,8 +145,7 @@ struct stream *stream_dup(const struct stream *s) STREAM_VERIFY_SANE(s); - if ((snew = stream_new(s->endp)) == NULL) - return NULL; + snew = stream_new(s->endp); return (stream_copy(snew, s)); } From d9db1a4092300970f9112c67556c1f4e860dabe0 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 15 Jun 2022 10:22:29 -0400 Subject: [PATCH 2/2] zebra: stream_dup cannot fail If stream_dup was unable to actually allocate memory then FRR would crash instead. So let's remove the check for null since it is not needed. Signed-off-by: Donald Sharp --- zebra/zebra_ptm.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/zebra/zebra_ptm.c b/zebra/zebra_ptm.c index fda5ef02cf..3127d2d304 100644 --- a/zebra/zebra_ptm.c +++ b/zebra/zebra_ptm.c @@ -1294,10 +1294,6 @@ static void zebra_ptm_send_bfdd(struct stream *msg) /* Create copy for replication. */ msgc = stream_dup(msg); - if (msgc == NULL) { - zlog_debug("%s: not enough memory", __func__); - return; - } /* Send message to all running BFDd daemons. */ for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client)) { @@ -1308,10 +1304,6 @@ static void zebra_ptm_send_bfdd(struct stream *msg) /* Allocate more messages. */ msg = stream_dup(msgc); - if (msg == NULL) { - zlog_debug("%s: not enough memory", __func__); - return; - } } stream_free(msgc); @@ -1326,10 +1318,6 @@ static void zebra_ptm_send_clients(struct stream *msg) /* Create copy for replication. */ msgc = stream_dup(msg); - if (msgc == NULL) { - zlog_debug("%s: not enough memory", __func__); - return; - } /* Send message to all running client daemons. */ for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client)) { @@ -1340,10 +1328,6 @@ static void zebra_ptm_send_clients(struct stream *msg) /* Allocate more messages. */ msg = stream_dup(msgc); - if (msg == NULL) { - zlog_debug("%s: not enough memory", __func__); - return; - } } stream_free(msgc);