From: Eric Blake <eblake@redhat.com>
To: Murilo Opsfelder Araujo <muriloo@linux.ibm.com>, qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>,
David Hildenbrand <david@redhat.com>,
Eduardo Habkost <ehabkost@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
qemu-trivial <qemu-trivial@nongnu.org>
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH] HACKING: document preference for g_new instead of g_malloc
Date: Tue, 15 May 2018 13:11:39 -0500 [thread overview]
Message-ID: <7abb9c3c-524d-16cb-4bbd-7a27c5c6e676@redhat.com> (raw)
In-Reply-To: <20180515134950.3755-1-muriloo@linux.ibm.com>
adding qemu-trivial as a potential tree for this to go through
On 05/15/2018 08:49 AM, Murilo Opsfelder Araujo wrote:
> This patch documents the preference for g_new instead of g_malloc. The
> reasons were adapted from commit b45c03f585ea9bb1af76c73e82195418c294919d.
>
> Discussion in QEMU's mailing list:
> http://lists.nongnu.org/archive/html/qemu-devel/2018-05/msg03238.html
>
> Cc: qemu-devel@nongnu.org
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Eduardo Habkost <ehabkost@redhat.com>
> Cc: Markus Armbruster <armbru@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Murilo Opsfelder Araujo <muriloo@linux.ibm.com>
> ---
> HACKING | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/HACKING b/HACKING
> index 4125c97d8d..0fc3e0fc04 100644
> --- a/HACKING
> +++ b/HACKING
> @@ -118,6 +118,15 @@ Please note that g_malloc will exit on allocation failure, so there
> is no need to test for failure (as you would have to with malloc).
> Calling g_malloc with a zero size is valid and will return NULL.
>
> +Prefer g_new(T, n) instead of g_malloc(sizeof(T) * n) for the following
> +reasons:
> +
> + a. It catches multiplication overflowing size_t;
> + b. It returns T * instead of void *, letting compiler catch more type
> + errors.
> +
> +Declarations like T *v = g_malloc(sizeof(*v)) are acceptable, though.
> +
> Memory allocated by qemu_memalign or qemu_blockalign must be freed with
> qemu_vfree, since breaking this will cause problems on Win32.
>
>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
parent reply other threads:[~2018-05-15 18:11 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20180515134950.3755-1-muriloo@linux.ibm.com>]
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=7abb9c3c-524d-16cb-4bbd-7a27c5c6e676@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=david@redhat.com \
--cc=ehabkost@redhat.com \
--cc=muriloo@linux.ibm.com \
--cc=pbonzini@redhat.com \
--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).