From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: dinglimin <dinglimin@cmss.chinamobile.com>,
richard.henderson@linaro.org, qemu-devel@nongnu.org,
"Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc
Date: Mon, 26 Feb 2024 10:03:50 +0000 [thread overview]
Message-ID: <ZdxiBvKPrynexuZl@redhat.com> (raw)
In-Reply-To: <2b3f15a8-93ba-4d4f-bfd6-7af11aade2dc@linaro.org>
On Mon, Feb 26, 2024 at 10:48:14AM +0100, Philippe Mathieu-Daudé wrote:
> Hi,
>
> On 26/2/24 10:06, dinglimin wrote:
> > Signed-off-by: dinglimin <dinglimin@cmss.chinamobile.com>
> > ---
> > semihosting/uaccess.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c
> > index dc587d73bc..7788ead9b2 100644
> > --- a/semihosting/uaccess.c
> > +++ b/semihosting/uaccess.c
> > @@ -14,10 +14,10 @@
> > void *uaccess_lock_user(CPUArchState *env, target_ulong addr,
> > target_ulong len, bool copy)
> > {
> > - void *p = malloc(len);
> > + void *p = g_try_malloc(len);
> > if (p && copy) {
> > if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) {
> > - free(p);
> > + g_free(p);
> > p = NULL;
> > }
> > }
>
> This seems dangerous, now all users of uaccess_lock_user() must
> use g_free(), in particular lock_user_string() which is used more
> than a hundred of times:
This is not true for many years now.
GLib is hardcoded to always use the system allocator, so g_malloc
can be freely mixed with free, and vica-verca.
Using 'g_free' is stylistically preferred, but not functionally
required.
>
> $ git grep -w lock_user_string | wc -l
> 116
>
> > @@ -87,5 +87,5 @@ void uaccess_unlock_user(CPUArchState *env, void *p,
> > if (len) {
> > cpu_memory_rw_debug(env_cpu(env), addr, p, len, 1);
> > }
> > - free(p);
> > + g_free(p);
> > }
>
>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2024-02-26 10:04 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-26 9:06 [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc dinglimin
2024-02-26 9:48 ` Philippe Mathieu-Daudé
2024-02-26 10:03 ` Daniel P. Berrangé [this message]
2024-02-26 10:16 ` Peter Maydell
2024-02-26 10:02 ` Zhao Liu
-- strict thread matches above, loose matches on Subject: below --
2023-07-25 8:06 dinglimin
2023-07-25 8:13 ` Michael Tokarev
2023-07-25 9:00 ` dinglimin
2023-07-25 9:13 ` Michael Tokarev
2023-07-25 9:35 ` Peter Maydell
2023-07-26 4:37 ` 回复: " dinglimin
2023-07-26 9:43 ` Peter Maydell
2023-07-26 15:21 ` Richard Henderson
2023-07-27 14:56 ` Peter Maydell
2023-07-27 15:04 ` Daniel P. Berrangé
2023-07-27 16:31 ` Richard Henderson
2023-07-28 5:12 ` dinglimin
2023-07-28 9:35 ` Peter Maydell
2023-07-28 10:50 ` dinglimin
2023-07-28 11:27 ` Peter Maydell
2023-07-28 12:16 ` Peter Maydell
2023-07-26 7:07 ` dinglimin
2023-07-25 10:57 ` dinglimin
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=ZdxiBvKPrynexuZl@redhat.com \
--to=berrange@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=dinglimin@cmss.chinamobile.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--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).