mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bernd Petrovitsch <bernd@firmix.at>
To: Jan Engelhardt <jengelh@linux01.gwdg.de>
Cc: Pavel Machek <pavel@ucw.cz>, Amit Choudhary <amit2030@yahoo.com>,
	Linux Kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] [DISCUSS] Make the variable NULL after freeing it.
Date: Sun, 31 Dec 2006 14:38:32 +0100	[thread overview]
Message-ID: <1167572312.3318.47.camel@gimli.at.home> (raw)
In-Reply-To: <Pine.LNX.4.61.0612280952450.15825@yvahk01.tjqt.qr>

On Thu, 2006-12-28 at 09:54 +0100, Jan Engelhardt wrote:
> On Dec 27 2006 17:10, Pavel Machek wrote:
> 
> >> Was just wondering if the _var_ in kfree(_var_) could be set to
> >> NULL after its freed. It may solve the problem of accessing some
> >> freed memory as the kernel will crash since _var_ was set to NULL.
> >> 
> >> Does this make sense? If yes, then how about renaming kfree to
> >> something else and providing a kfree macro that would do the
> >> following:
> >> 
> >> #define kfree(x) do { \
> >>                       new_kfree(x); \
> >>                       x = NULL; \
> >>                     } while(0)
> >> 
> >> There might be other better ways too.

----  snip  ----
(x) = NULL; \
----  snip  ----
?

> >No, that would be very confusing. Otoh having
> >KFREE() do kfree() and assignment might be acceptable.
> 
> What about setting x to some poison value from <linux/poison.h>?

That depends on the decision/definition if (so called) "double free" is
an error or not (and "free(NULL)" must work in POSIX-compliant
environments).
Personally I think it is pointless to disallow "kfree(NULL)" by using
some poison value and force people to add a "we have to free that
variable" variable to work around it instead of keeping it NULL (which
makes the "kfree($variable)" a no-op).
Former discussions are to be found in the archives ......

	Bernd
-- 
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services


  reply	other threads:[~2006-12-31 13:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-21 23:41 Amit Choudhary
2006-12-27 17:10 ` Pavel Machek
2006-12-28  8:54   ` Jan Engelhardt
2006-12-31 13:38     ` Bernd Petrovitsch [this message]
2007-01-01  0:43       ` Ingo Oeser
2007-01-01  1:05         ` YOSHIFUJI Hideaki / 吉藤英明
2007-01-01  6:37         ` Amit Choudhary
2007-01-01 16:09           ` Ingo Oeser
2007-01-01 16:25             ` Andreas Schwab
2007-01-01 21:40               ` Ingo Oeser
2007-01-01 21:42                 ` Jan Engelhardt
2007-01-01 18:36             ` Pavel Machek

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=1167572312.3318.47.camel@gimli.at.home \
    --to=bernd@firmix.at \
    --cc=amit2030@yahoo.com \
    --cc=jengelh@linux01.gwdg.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pavel@ucw.cz \
    /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®