From: Laurent Vivier <laurent@vivier.eu>
To: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>, qemu-devel@nongnu.org
Cc: tony.nguyen@bt.com, alex.bennee@linaro.org, armbru@redhat.com
Subject: Re: [PATCH v4 1/3] tests/migration: mem leak fix
Date: Wed, 23 Oct 2019 11:45:02 +0200 [thread overview]
Message-ID: <e231ec9f-5e2d-2ca5-33cb-2571e47c2561@vivier.eu> (raw)
In-Reply-To: <95ceba2addaa3136db8ee233ea2e0ff9d13db7c0.1570208781.git.maozhongyi@cmss.chinamobile.com>
Le 04/10/2019 à 19:32, Mao Zhongyi a écrit :
> ‘data’ has the possibility of memory leaks, so use the
> glib macros g_autofree recommended by CODING_STYLE.rst
> to automatically release the memory that returned from
> g_malloc().
>
> Signed-off-by: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> tests/migration/stress.c | 21 ++-------------------
> 1 file changed, 2 insertions(+), 19 deletions(-)
>
> diff --git a/tests/migration/stress.c b/tests/migration/stress.c
> index d9aa4afe92..d8a6f64af0 100644
> --- a/tests/migration/stress.c
> +++ b/tests/migration/stress.c
> @@ -170,26 +170,14 @@ static unsigned long long now(void)
> static int stressone(unsigned long long ramsizeMB)
> {
> size_t pagesPerMB = 1024 * 1024 / PAGE_SIZE;
> - char *ram = malloc(ramsizeMB * 1024 * 1024);
> + g_autofree char *ram = g_malloc(ramsizeMB * 1024 * 1024);
> char *ramptr;
> size_t i, j, k;
> - char *data = malloc(PAGE_SIZE);
> + g_autofree char *data = g_malloc(PAGE_SIZE);
> char *dataptr;
> size_t nMB = 0;
> unsigned long long before, after;
>
> - if (!ram) {
> - fprintf(stderr, "%s (%05d): ERROR: cannot allocate %llu MB of RAM: %s\n",
> - argv0, gettid(), ramsizeMB, strerror(errno));
> - return -1;
> - }
> - if (!data) {
> - fprintf(stderr, "%s (%d): ERROR: cannot allocate %d bytes of RAM: %s\n",
> - argv0, gettid(), PAGE_SIZE, strerror(errno));
> - free(ram);
> - return -1;
> - }
> -
> /* We don't care about initial state, but we do want
> * to fault it all into RAM, otherwise the first iter
> * of the loop below will be quite slow. We cna't use
> @@ -198,8 +186,6 @@ static int stressone(unsigned long long ramsizeMB)
> memset(ram, 0xfe, ramsizeMB * 1024 * 1024);
>
> if (random_bytes(data, PAGE_SIZE) < 0) {
> - free(ram);
> - free(data);
> return -1;
> }
>
> @@ -227,9 +213,6 @@ static int stressone(unsigned long long ramsizeMB)
> }
> }
> }
> -
> - free(data);
> - free(ram);
> }
>
>
>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
next prev parent reply other threads:[~2019-10-23 9:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-04 17:32 [PATCH v4 0/3] some fix in tests/migration Mao Zhongyi
2019-10-04 17:32 ` [PATCH v4 1/3] tests/migration: mem leak fix Mao Zhongyi
2019-10-23 9:45 ` Laurent Vivier [this message]
2019-10-04 17:32 ` [PATCH v4 2/3] tests/migration: fix a typo in comment Mao Zhongyi
2019-10-21 16:15 ` Laurent Vivier
2019-10-04 17:32 ` [PATCH v4 3/3] tests/migration:fix unreachable path in stress test Mao Zhongyi
2019-10-23 8:05 ` Laurent Vivier
2019-10-23 3:30 ` [PATCH v4 0/3] some fix in tests/migration maozy
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=e231ec9f-5e2d-2ca5-33cb-2571e47c2561@vivier.eu \
--to=laurent@vivier.eu \
--cc=alex.bennee@linaro.org \
--cc=armbru@redhat.com \
--cc=maozhongyi@cmss.chinamobile.com \
--cc=qemu-devel@nongnu.org \
--cc=tony.nguyen@bt.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).