From: Anand Jain <Anand.Jain@oracle.com>
To: Wang Shilong <wangshilong1991@gmail.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] Btrfs-progs: fix memory leak in open_file_or_dir()
Date: Wed, 10 Jul 2013 11:43:16 +0800 [thread overview]
Message-ID: <51DCD854.8050401@oracle.com> (raw)
In-Reply-To: <1373410908-2274-1-git-send-email-wangshilong1991@gmail.com>
Thanks.
Reviewed-by: Anand Jain <anand.jain@oracle.com>
On 07/10/2013 07:01 AM, Wang Shilong wrote:
> From: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
>
> After calling opendir() successfully, closedir() should be
> also called to free memory. Otherwise, memory leak happens.
>
> Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
> ---
> utils.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/utils.c b/utils.c
> index 7b4cd74..0afff55 100644
> --- a/utils.c
> +++ b/utils.c
> @@ -1480,7 +1480,7 @@ int open_file_or_dir(const char *fname)
> {
> int ret;
> struct stat st;
> - DIR *dirstream;
> + DIR *dirstream = NULL;
> int fd;
>
> ret = stat(fname, &st);
> @@ -1496,9 +1496,10 @@ int open_file_or_dir(const char *fname)
> } else {
> fd = open(fname, O_RDWR);
> }
> - if (fd < 0) {
> - return -3;
> - }
> + if (fd < 0)
> + fd = -3;
> + if (dirstream)
> + closedir(dirstream);
> return fd;
> }
>
>
next prev parent reply other threads:[~2013-07-10 3:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-09 23:01 [PATCH] Btrfs-progs: fix memory leak in open_file_or_dir() Wang Shilong
2013-07-10 3:43 ` Anand Jain [this message]
2013-07-14 8:33 ` anand jain
2013-07-14 8:46 ` [PATCH] From: Wang Shilong <wangsl.fnst@cn.fujitsu.com> Anand Jain
2013-07-14 8:48 ` [PATCH v2] Btrfs-progs: fix memory leak in open_file_or_dir() Anand Jain
2013-07-14 13:58 ` Wang Shilong
2013-07-14 14:40 ` anand jain
2013-07-14 14:51 ` Wang Shilong
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=51DCD854.8050401@oracle.com \
--to=anand.jain@oracle.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=wangshilong1991@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 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.