From: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
To: qemu-devel@nongnu.org
Cc: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
Subject: [PATCH 1/9] tests/migration: mem leak fix
Date: Wed, 3 Jun 2020 16:08:56 +0800 [thread overview]
Message-ID: <20200603080904.997083-2-maozhongyi@cmss.chinamobile.com> (raw)
In-Reply-To: <20200603080904.997083-1-maozhongyi@cmss.chinamobile.com>
‘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>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
---
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 0c23964693..f9626d50ee 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 can'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);
}
--
2.17.1
next prev parent reply other threads:[~2020-06-03 8:13 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-03 8:08 [PATCH 0/9] monitor/hmp-cmds: small improvements for migration Mao Zhongyi
2020-06-03 8:08 ` Mao Zhongyi [this message]
2020-06-03 8:08 ` [PATCH 2/9] tests/migration: fix unreachable path in stress test Mao Zhongyi
2020-06-03 8:08 ` [PATCH 3/9] monitor/hmp-cmds: add units for migrate_parameters Mao Zhongyi
2020-06-03 8:08 ` [PATCH 4/9] monitor/hmp-cmds: don't silently output when running 'migrate_set_downtime' fails Mao Zhongyi
2020-06-03 8:09 ` [PATCH 5/9] monitor/hmp-cmds: delete redundant Error check before invoke hmp_handle_error() Mao Zhongyi
2020-06-11 18:52 ` Dr. David Alan Gilbert
2020-06-03 8:09 ` [PATCH 6/9] monitor/hmp-cmds: add 'goto end' to reduce duplicate code Mao Zhongyi
2020-06-11 18:56 ` Dr. David Alan Gilbert
2020-06-03 8:09 ` [PATCH 7/9] monitor/hmp-cmds: improvements for the 'info migrate' Mao Zhongyi
2020-06-11 18:57 ` Dr. David Alan Gilbert
2020-06-03 8:09 ` [PATCH 8/9] docs/xbzrle: update 'cache miss rate' and 'encoding rate' to docs Mao Zhongyi
2020-06-11 19:00 ` Dr. David Alan Gilbert
2020-06-03 8:09 ` [PATCH 9/9] migration/ram: calculate un/encoded_size only when needed Mao Zhongyi
2020-06-11 19:05 ` Dr. David Alan Gilbert
2020-06-12 3:06 ` [PATCH 9/9] migration/ram: calculate un/encoded_size only whenneeded 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=20200603080904.997083-2-maozhongyi@cmss.chinamobile.com \
--to=maozhongyi@cmss.chinamobile.com \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).