All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
To: qemu-devel@nongnu.org
Cc: tony.nguyen@bt.com, alex.bennee@linaro.org, armbru@redhat.com,
	Mao Zhongyi <maozhongyi@cmss.chinamobile.com>,
	laurent@vivier.eu
Subject: [Qemu-devel] [PATCH v2 1/3] tests/migration: mem leak fix
Date: Wed, 11 Sep 2019 11:31:02 +0800	[thread overview]
Message-ID: <9b8662b94d89030b1f33193246c645baac2eedd7.1568170994.git.maozhongyi@cmss.chinamobile.com> (raw)
In-Reply-To: <cover.1568170994.git.maozhongyi@cmss.chinamobile.com>
In-Reply-To: <cover.1568170994.git.maozhongyi@cmss.chinamobile.com>

‘data’ has the possibility of memory leaks, so use the
glic macros g_autofree recommended by CODING_STYLE.rst
to automatically release the memory that returned from
g_malloc().

Cc: armbru@redhat.com
Cc: laurent@vivier.eu
Cc: tony.nguyen@bt.com
Cc: alex.bennee@linaro.org

Signed-off-by: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
---
 tests/migration/stress.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index d9aa4afe92..6cbb2d49d3 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -170,10 +170,10 @@ 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 = malloc(ramsizeMB * 1024 * 1024);
     char *ramptr;
     size_t i, j, k;
-    char *data = malloc(PAGE_SIZE);
+    g_autofree char *data = malloc(PAGE_SIZE);
     char *dataptr;
     size_t nMB = 0;
     unsigned long long before, after;
@@ -186,7 +186,6 @@ static int stressone(unsigned long long ramsizeMB)
     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;
     }
 
@@ -198,8 +197,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 +224,6 @@ static int stressone(unsigned long long ramsizeMB)
             }
         }
     }
-
-    free(data);
-    free(ram);
 }
 
 
-- 
2.17.1





  reply	other threads:[~2019-09-11  3:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-11  3:31 [Qemu-devel] [PATCH v2 0/3] some fix in tests/migration Mao Zhongyi
2019-09-11  3:31 ` Mao Zhongyi [this message]
2019-09-11  8:21   ` [Qemu-devel] [PATCH v2 1/3] tests/migration: mem leak fix Alex Bennée
2019-10-01 15:31   ` Laurent Vivier
2019-10-03  5:34     ` maozy
2019-09-11  3:31 ` [Qemu-devel] [PATCH v2 2/3] tests/migration: fix a typo in comment Mao Zhongyi
2019-10-01 15:31   ` Laurent Vivier
2019-10-04 14:23   ` [Qemu-devel] " Philippe Mathieu-Daudé
2019-09-11  3:31 ` [Qemu-devel] [PATCH v2 3/3] tests/migration:fix unreachable path in stress test Mao Zhongyi
2019-10-01 15:22   ` maozy
2019-10-01 15:46   ` Laurent Vivier
2019-10-03  7:17     ` _[PATCH_v2_3/3]_tests/migration:fix_unreachable_path_in_stress_test maozy
2019-10-03  9:23       ` _[PATCH_v2_3/3]_tests/migration:fix_unreachable_path_in_stress_test Laurent Vivier
2019-10-04  1:59         ` _[PATCH_v2_3/3]_tests/migration:fix_unreachable_path_in_stress_test 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=9b8662b94d89030b1f33193246c645baac2eedd7.1568170994.git.maozhongyi@cmss.chinamobile.com \
    --to=maozhongyi@cmss.chinamobile.com \
    --cc=alex.bennee@linaro.org \
    --cc=armbru@redhat.com \
    --cc=laurent@vivier.eu \
    --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 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.