mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jesper Juhl <juhl-lkml@dif.dk>
To: Ralph Corderoy <ralph@inputplus.co.uk>
Cc: Jesper Juhl <juhl-lkml@dif.dk>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] don't do pointless NULL checks and casts before kfree() in security/
Date: Sun, 20 Mar 2005 14:18:04 +0100 (CET)	[thread overview]
Message-ID: <Pine.LNX.4.62.0503201407220.2501@dragon.hyggekrogen.localhost> (raw)
In-Reply-To: <200503201250.j2KCoAq11871@blake.inputplus.co.uk>

On Sun, 20 Mar 2005, Ralph Corderoy wrote:

> 
> Hi Jesper,
> 
> > kfree() handles NULL pointers, so checking a pointer for NULL before 
> > calling kfree() on it is pointless.
> 
> Not necessarily.  It helps tell the reader that the pointer may be NULL
> at that point.  This has come up before.
> 
>     http://groups-beta.google.com/group/linux.kernel/browse_thread/thread/bd3d6e5a29e43c73/7b43819f874295e8?q=ralph@inputplus.co.uk+persuade+lkml#7b43819f874295e8
> 

I agree that

	if (foo->bar) {
		kfree(foo->bar);
		foo->bar = NULL;
	}

makes it easy to see that foo->bar might be NULL, but I think the 
advantages of simply

	kfree(foo->bar);
	foo->bar = NULL;

outweigh that.

Having to remember that kfree(NULL) is valid shouldn't be hard, people 
should be used to that from userspace code calling free(), and if there 
are places where it's important to remember that the pointer might be 
NULL, then a simple comment would do, wouldn't it?

	kfree(foo->bar);	/* kfree(NULL) is valid */

the short version also have the real bennefits of generating shorter and 
faster code as well as being shorter "on-screen".


-- 
Jesper Juhl


  reply	other threads:[~2005-03-20 13:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-20 12:29 Jesper Juhl
2005-03-20 12:50 ` Ralph Corderoy
2005-03-20 13:18   ` Jesper Juhl [this message]
2005-03-20 13:31     ` Ralph Corderoy
2005-03-20 14:04       ` YOSHIFUJI Hideaki / 吉藤英明
2005-03-20 14:39       ` Jesper Juhl
2005-03-21 10:17         ` Ralph Corderoy
2005-03-22 15:00 ` Stephen Smalley
2005-03-22 20:57   ` [PATCH] don't do pointless NULL checks and casts before kfree() in security/selinux/ Jesper Juhl
2005-03-22 15:34 ` [PATCH] don't do pointless NULL checks and casts before kfree() in security/ David Howells
2005-03-22 20:46   ` Jesper Juhl
     [not found] <fa.p25ihnj.4026at@ifi.uio.no>
     [not found] ` <fa.iqmuavi.o6kfai@ifi.uio.no>
2005-03-20 13:18   ` Bodo Eggert

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=Pine.LNX.4.62.0503201407220.2501@dragon.hyggekrogen.localhost \
    --to=juhl-lkml@dif.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ralph@inputplus.co.uk \
    /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

all inboxes | Powered by JetHome®