linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
To: Nilanjan Roychowdhury <nilanjan.roychowdhury@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>,
	linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] mtd: mtdoops: fix for a potential memory leak in mtdoops_notify_remove
Date: Mon, 12 Aug 2013 14:26:50 -0300	[thread overview]
Message-ID: <20130812172649.GB7198@localhost> (raw)
In-Reply-To: <1376251908-7451-1-git-send-email-nilanjan.roychowdhury@gmail.com>

On Sun, Aug 11, 2013 at 01:11:48PM -0700, Nilanjan Roychowdhury wrote:
> we are allocating cxt->oops_page_used using vmalloc in mtdoops_notify_add for
> every mtd_info addition but not freeing it in mtdoops_notify_remove
> 
> Signed-off-by: Nilanjan Roychowdhury <nilanjan.roychowdhury@gmail.com>
> ---
>  drivers/mtd/mtdoops.c |    1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
> index 97bb8f6..02f49aa 100644
> --- a/drivers/mtd/mtdoops.c
> +++ b/drivers/mtd/mtdoops.c
> @@ -386,6 +386,7 @@ static void mtdoops_notify_remove(struct mtd_info *mtd)
>  	cxt->mtd = NULL;
>  	flush_work(&cxt->work_erase);
>  	flush_work(&cxt->work_write);
> +	vfree(cxt->oops_page_used);
>  }
>  
> -- 
> 1.7.9.5
> 

Have you tested this patch doing an unregister/module remove cycle?

I'm not entirely sure, but I *think* you must also remove the
vfree(cxt->oops_page_used); at mtdoops_exit(). Otherwise,
you might call vfree() twice, the second time on a garbage pointer.

The reason for this is that the unregister_mtd_user(&mtdoops_notifier);
call in mtdoops_exit() will call the .remove callback (causing the first
vfree() with this patch) and then call vfree() for the second time, explicitly.
-- 
Ezequiel García, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com

  reply	other threads:[~2013-08-12 17:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-11 20:11 [PATCH 1/1] mtd: mtdoops: fix for a potential memory leak in mtdoops_notify_remove Nilanjan Roychowdhury
2013-08-12 17:26 ` Ezequiel Garcia [this message]
2013-08-13  4:11   ` Nilanjan Roychowdhury

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=20130812172649.GB7198@localhost \
    --to=ezequiel.garcia@free-electrons.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=nilanjan.roychowdhury@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).