mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Alexander Beregalov <a.beregalov@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kernel/resource.c: fix memory leak
Date: Sat, 9 Jan 2010 09:34:45 -0800 (PST)	[thread overview]
Message-ID: <alpine.LFD.2.00.1001090933040.7821@localhost.localdomain> (raw)
In-Reply-To: <1263048395-14873-1-git-send-email-a.beregalov@gmail.com>



On Sat, 9 Jan 2010, Alexander Beregalov wrote:
>
> Free res before exit.
> Found by cppcheck.
> 
> Signed-off-by: Alexander Beregalov <a.beregalov@gmail.com>
> ---
>  kernel/resource.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/kernel/resource.c b/kernel/resource.c
> index af96c1e..ae2e177 100644
> --- a/kernel/resource.c
> +++ b/kernel/resource.c
> @@ -545,11 +545,12 @@ static void __init __reserve_region_with_split(struct resource *root,
>  	res->flags = IORESOURCE_BUSY;
>  
>  	conflict = __request_resource(parent, res);
> +	kfree(res);
> +
>  	if (!conflict)
>  		return;
>  
>  	/* failed, split and try again */
> -	kfree(res);

As Amerigo pointed out, this is very wrong indeed.

If we don't have a conflict, then __request_resource() will have inserted 
the resource into the resource tree, and we absolutely must _not_ free it.

So that cppcheck tool is way too simplistic, and wrong.

			Linus

      parent reply	other threads:[~2010-01-09 17:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-09 14:46 Alexander Beregalov
2010-01-09 16:57 ` Américo Wang
2010-01-09 17:34 ` Linus Torvalds [this message]

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=alpine.LFD.2.00.1001090933040.7821@localhost.localdomain \
    --to=torvalds@linux-foundation.org \
    --cc=a.beregalov@gmail.com \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®