All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jim Meyering <jim@meyering.net>
To: Project Hail <hail-devel@vger.kernel.org>
Subject: [PATCH tabled] server/server.c don't deref NULL on failed malloc
Date: Thu, 23 Sep 2010 13:03:15 +0200	[thread overview]
Message-ID: <87zkv8wwlo.fsf@meyering.net> (raw)



Signed-off-by: Jim Meyering <meyering@redhat.com>
---
Just noticed that sometimes tabled uses this idiom:
  if (!(key = malloc(klen + 1)))
and sometimes this:
  if ((key = malloc(klen + 1)) == NULL)
This time I used "... == NULL".

 server/server.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/server/server.c b/server/server.c
index 2b4ef1c..3cec5ae 100644
--- a/server/server.c
+++ b/server/server.c
@@ -306,7 +306,8 @@ static char *pathtokey(const char *path)
 		return NULL;
 	klen = end - path;

-	key = malloc(klen + 1);
+	if ((key = malloc(klen + 1)) == NULL)
+		return NULL;
 	memcpy(key, path, klen);
 	key[klen] = 0;

--
1.7.3.234.g7bba3

             reply	other threads:[~2010-09-23 11:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-23 11:03 Jim Meyering [this message]
2010-09-23 14:07 ` [PATCH tabled] server/server.c don't deref NULL on failed malloc Pete Zaitcev
2010-09-23 19:41   ` Jeff Garzik

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=87zkv8wwlo.fsf@meyering.net \
    --to=jim@meyering.net \
    --cc=hail-devel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.