qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: haris iqbal <haris.phnx@gmail.com>
Cc: QEMU Trivial <qemu-trivial@nongnu.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Markus Armbruster <armbru@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>
Subject: Re: [Qemu-devel] [Qemu-Devel] [PATCH] Changed malloc to g_malloc, free to g_free in linux-user/qemu.h
Date: Thu, 31 Mar 2016 10:42:09 +0100	[thread overview]
Message-ID: <20160331094209.GK32185@stefanha-x1.localdomain> (raw)
In-Reply-To: <CAE_WKMz4K1hSqwrLzgAPP2BMjokY_E6-R61R2RyRS06Pteb80w@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1779 bytes --]

On Wed, Mar 30, 2016 at 09:58:41PM +0530, haris iqbal wrote:
> On Wed, Mar 30, 2016 at 7:39 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote:
> > On Thu, Mar 24, 2016 at 12:02:03AM +0530, Md Haris Iqbal wrote:
> >> Signed-off-by: Md Haris Iqbal <haris.phnx@gmail.com>
> >> ---
> >>  linux-user/qemu.h | 4 ++--
> >>  1 file changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/linux-user/qemu.h b/linux-user/qemu.h
> >> index 26b0ba2..3c3fd15 100644
> >> --- a/linux-user/qemu.h
> >> +++ b/linux-user/qemu.h
> >> @@ -381,7 +381,7 @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy
> >>  #ifdef DEBUG_REMAP
> >>      {
> >>          void *addr;
> >> -        addr = malloc(len);
> >> +        addr = g_malloc(len);
> >>          if (copy)
> >>              memcpy(addr, g2h(guest_addr), len);
> >>          else
> >> @@ -407,7 +407,7 @@ static inline void unlock_user(void *host_ptr, abi_ulong guest_addr,
> >>          return;
> >>      if (len > 0)
> >>          memcpy(g2h(guest_addr), host_ptr, len);
> >> -    free(host_ptr);
> >> +    g_free(host_ptr);
> >>  #endif
> >>  }
> >
> > If I understand correctly either lock_user() or lock_user_string() may
> > be followed by unlock_user().  If you change unlock_user() to g_free()
> > then you also need to change lock_user_string() to g_malloc() to avoid a
> > malloc()/g_free() mismatch.
> 
> lock_user_string() does not use malloc itself, but calls lock_user()
> from itself.

You are right.  The reason I got confused is because there are 3
versions of lock_user(): linux-user, bsd-user, and
include/exec/softmmu-semi.h.

Please send equivalent patches for the other 2 versions as well.  This
way they stay consistent.

Thanks,
Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

  reply	other threads:[~2016-03-31  9:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-23 18:32 [Qemu-devel] [Qemu-Devel] [PATCH] Changed malloc to g_malloc, free to g_free in linux-user/qemu.h Md Haris Iqbal
2016-03-29 15:53 ` haris iqbal
2016-03-30 14:06   ` haris iqbal
2016-03-30 14:09 ` Stefan Hajnoczi
2016-03-30 16:28   ` haris iqbal
2016-03-31  9:42     ` Stefan Hajnoczi [this message]
2016-03-31 10:57       ` haris iqbal
2016-05-03  9:47         ` haris iqbal
2016-05-05 17:26 ` Stefan Hajnoczi
2016-09-14  7:24 ` [Qemu-devel] " Michael Tokarev

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=20160331094209.GK32185@stefanha-x1.localdomain \
    --to=stefanha@gmail.com \
    --cc=armbru@redhat.com \
    --cc=haris.phnx@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@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).