From: "Wei, Jiangang" <weijg.fnst@cn.fujitsu.com>
To: "alexey.kodanev@oracle.com" <alexey.kodanev@oracle.com>
Cc: "ltp-list@lists.sourceforge.net" <ltp-list@lists.sourceforge.net>
Subject: Re: [LTP] [PATCH 3/3] kernel/mem/mmapstress: fix resource leak
Date: Fri, 8 May 2015 06:42:26 +0000 [thread overview]
Message-ID: <1431067342.1760.10.camel@localhost> (raw)
In-Reply-To: <554B7127.7000606@oracle.com>
On Thu, 2015-05-07 at 17:05 +0300, Alexey Kodanev wrote:
> On 05/06/2015 01:18 PM, Wei,Jiangang wrote:
> > Including memory and fd leak.
> >
> > Signed-off-by: Wei,Jiangang <weijg.fnst@cn.fujitsu.com>
> > ---
> > testcases/kernel/mem/mmapstress/mmapstress01.c | 7 +++++++
> > 1 file changed, 7 insertions(+)
> >
> > diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c
> > index 0baf0e2..1db8147 100644
> > --- a/testcases/kernel/mem/mmapstress/mmapstress01.c
> > +++ b/testcases/kernel/mem/mmapstress/mmapstress01.c
> > @@ -657,6 +657,8 @@ int fileokay(char *file, uchar_t * expbuf)
> > perror("read error");
> > /***** LTP Port *****/
> > local_flag = FAILED;
> > + free(readbuf);
>
> We could allocate readbuf on the stack... readbuf[pagesize] so free()
> not needed.
Thanks for your comments.
Yes, That's right.
I accept it.
>
> > + close(fd);
> > anyfail();
>
> anyfail() calls tst_brkm() - the program terminates and closes fd.
>
> > /***** ** *****/
> > return 0;
> > @@ -668,6 +670,8 @@ int fileokay(char *file, uchar_t * expbuf)
> > (void)fprintf(stderr, "read %d of %ld bytes\n",
> > (i * pagesize) + cnt,
> > (long)mapsize);
> > + free(readbuf);
> > + close(fd);
> > return 0;
> > }
> > }
> > @@ -688,10 +692,13 @@ int fileokay(char *file, uchar_t * expbuf)
> > "(fsize %ld)\n", i, j,
> > statbuf.st_size);
> > #endif /* LARGE_FILE */
> > + free(readbuf);
> > + close(fd);
> > return 0;
>
> In both above cases it'll call anyfail() after checking fileokay()'s
> return value.
> If it seems not obvious we can close 'fd' here and it'd be better to use
> SAFE_CLOSE() macro from safe_macros.h.
There's no cleanup function for SAFE_CLOSE().
so,
close() is the same as SAFE_CLOSE(NULL, fd).
And close(fd) had been used at mmapstress01.c.
if i adopt SAFE_CLOSE(NULL, fd),
It looks a bit odd...
Thanks,
Wei
>
> > }
> > }
> > }
> > + free(readbuf);
> > close(fd);
> >
> > return 1;
>
> Thanks,
> Alexey
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
next prev parent reply other threads:[~2015-05-08 6:42 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-06 10:18 [LTP] [PATCH 1/3] kernel/syscalls/fallocate: fix array parameter degradation Wei,Jiangang
2015-05-06 10:18 ` [LTP] [PATCH 2/3] kernel/syscalls/fallocate: specify size needs check Wei,Jiangang
2015-05-06 20:42 ` Alexey Kodanev
2015-05-07 4:53 ` Wei, Jiangang
2015-05-07 6:17 ` [LTP] [PATCH v2] kernel/syscalls/fallocate: fix array parameter degradation Wei,Jiangang
2015-05-07 9:37 ` Alexey Kodanev
2015-05-07 9:54 ` Wei, Jiangang
2015-05-12 5:43 ` Wanlong Gao
2015-05-12 5:44 ` Wanlong Gao
2015-05-12 5:52 ` Wei, Jiangang
2015-05-06 10:18 ` [LTP] [PATCH 3/3] kernel/mem/mmapstress: fix resource leak Wei,Jiangang
2015-05-07 14:05 ` Alexey Kodanev
2015-05-08 6:42 ` Wei, Jiangang [this message]
2015-05-12 9:12 ` Cyril Hrubis
2015-05-13 12:03 ` Alexey Kodanev
2015-05-08 6:47 ` [LTP] [PATCH v2] " Wei,Jiangang
2015-05-19 3:34 ` [LTP] [PATCH] mmapstress01: Modify readbuf's type and define it to uchar_t Zeng Linggang
2015-05-19 9:23 ` Jan Stancek
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=1431067342.1760.10.camel@localhost \
--to=weijg.fnst@cn.fujitsu.com \
--cc=alexey.kodanev@oracle.com \
--cc=ltp-list@lists.sourceforge.net \
/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