Netdev List
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: netdev@vger.kernel.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH iproute2] rt_names: check for malloc() failure
Date: Wed,  7 Jun 2023 18:34:54 -0700	[thread overview]
Message-ID: <20230608013454.15813-1-stephen@networkplumber.org> (raw)

Fixes issue reported by Gcc 13 analayzer.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/rt_names.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/rt_names.c b/lib/rt_names.c
index b441e98f8078..68db74e301ff 100644
--- a/lib/rt_names.c
+++ b/lib/rt_names.c
@@ -81,6 +81,10 @@ rtnl_hash_initialize(const char *file, struct rtnl_hash_entry **hash, int size)
 			continue;
 
 		entry = malloc(sizeof(*entry));
+		if (entry == NULL) {
+			fprintf(stderr, "malloc error: for entry\n");
+			break;
+		}
 		entry->id   = id;
 		entry->name = strdup(namebuf);
 		entry->next = hash[id & (size - 1)];
-- 
2.39.2


             reply	other threads:[~2023-06-08  1:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-08  1:34 Stephen Hemminger [this message]
2023-06-08  1:40 ` [PATCH iproute2] rt_names: check for malloc() failure patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230608013454.15813-1-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox