From: "Philippe Mathieu-Daudé" <philippe.mathieu.daude@gmail.com>
To: jianchunfu <jianchunfu@cmss.chinamobile.com>,
richard.henderson@linaro.org
Cc: quintela@redhat.com, qemu-devel@nongnu.org, dgilbert@redhat.com
Subject: Re: [PATCH] migration/dirtyrate: Replace malloc with g_new
Date: Mon, 11 Apr 2022 23:44:14 +0200 [thread overview]
Message-ID: <32abbd92-8cce-dffd-6bc3-df9ae83de64c@gmail.com> (raw)
In-Reply-To: <20220411094703.7000-1-jianchunfu@cmss.chinamobile.com>
On 11/4/22 11:47, jianchunfu wrote:
> Using macro g_new() to handling potential memory allocation failures
> in dirtyrate.
>
> Signed-off-by: jianchunfu <jianchunfu@cmss.chinamobile.com>
> ---
> migration/dirtyrate.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
> index aace12a787..0e59aacbb0 100644
> --- a/migration/dirtyrate.c
> +++ b/migration/dirtyrate.c
> @@ -522,10 +522,10 @@ static void calculate_dirtyrate_dirty_ring(struct DirtyRateConfig config)
> nvcpu++;
> }
>
> - dirty_pages = malloc(sizeof(*dirty_pages) * nvcpu);
> + dirty_pages = g_new(DirtyPageRecord, nvcpu);
>
> DirtyStat.dirty_ring.nvcpu = nvcpu;
> - DirtyStat.dirty_ring.rates = malloc(sizeof(DirtyRateVcpu) * nvcpu);
> + DirtyStat.dirty_ring.rates = g_new(DirtyRateVcpu, nvcpu);
>
> dirtyrate_global_dirty_log_start();
>
While malloc() resources are released with free(), g_malloc/g_new()
ones with g_free().
So to match the API, this hunk is missing:
-- >8 --
diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
index aace12a787..e49db7ca4c 100644
--- a/migration/dirtyrate.c
+++ b/migration/dirtyrate.c
@@ -159,3 +159,3 @@ static void cleanup_dirtyrate_stat(struct
DirtyRateConfig config)
if (dirtyrate_mode == DIRTY_RATE_MEASURE_MODE_DIRTY_RING) {
- free(DirtyStat.dirty_ring.rates);
+ g_free(DirtyStat.dirty_ring.rates);
DirtyStat.dirty_ring.rates = NULL;
@@ -558,3 +558,3 @@ static void calculate_dirtyrate_dirty_ring(struct
DirtyRateConfig config)
DirtyStat.dirty_rate = dirtyrate_sum;
- free(dirty_pages);
+ g_free(dirty_pages);
}
---
prev parent reply other threads:[~2022-04-11 21:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-11 9:47 [PATCH] migration/dirtyrate: Replace malloc with g_new jianchunfu
2022-04-11 11:30 ` Dr. David Alan Gilbert
2022-04-11 18:08 ` Richard Henderson
2022-04-11 21:44 ` Philippe Mathieu-Daudé [this message]
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=32abbd92-8cce-dffd-6bc3-df9ae83de64c@gmail.com \
--to=philippe.mathieu.daude@gmail.com \
--cc=dgilbert@redhat.com \
--cc=jianchunfu@cmss.chinamobile.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=richard.henderson@linaro.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).