[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] multi-process: Initialize variables declared with g_auto*
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [PATCH] multi-process: Initialize variables declared with g_auto* |
Date: |
Wed, 3 Mar 2021 11:08:08 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 |
Hi,
On 3/3/21 8:06 AM, Zenghui Yu wrote:
> Quote docs/devel/style.rst (section "Automatic memory deallocation"):
>
> * Variables declared with g_auto* MUST always be initialized,
> otherwise the cleanup function will use uninitialized stack memory
>
> Initialize @name properly to get rid of the compilation error:
>
> ../hw/remote/proxy.c: In function 'pci_proxy_dev_realize':
> /usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: error: 'name' may be
> used uninitialized in this function [-Werror=maybe-uninitialized]
> g_free (*pp);
> ^~~~~~~~~~~~
> ../hw/remote/proxy.c:350:30: note: 'name' was declared here
> g_autofree char *name;
> ^~~~
>
> Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
> ---
> hw/remote/memory.c | 3 +--
> hw/remote/proxy.c | 3 +--
> 2 files changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/hw/remote/memory.c b/hw/remote/memory.c
> index 32085b1e05..f5f735c15a 100644
> --- a/hw/remote/memory.c
> +++ b/hw/remote/memory.c
> @@ -43,9 +43,8 @@ void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp)
> remote_sysmem_reset();
>
> for (region = 0; region < msg->num_fds; region++) {
Could you move the suffix iteration out of the loop?
for (region = 0; region < msg->num_fds; region++, suffix++) {
> - g_autofree char *name;
> + g_autofree char *name = g_strdup_printf("remote-mem-%u", suffix++);
> subregion = g_new(MemoryRegion, 1);
> - name = g_strdup_printf("remote-mem-%u", suffix++);
> memory_region_init_ram_from_fd(subregion, NULL,
> name, sysmem_info->sizes[region],
> true, msg->fds[region],