[PATCH 0/7] hw/riscv: fix leak, add more g_autofree

Daniel Henrique Barboza posted 7 patches 10 months, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20240122221529.86562-1-dbarboza@ventanamicro.com
Maintainers: Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Bin Meng <bin.meng@windriver.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Sunil V L <sunilvl@ventanamicro.com>
hw/riscv/numa.c            |   4 +-
hw/riscv/virt-acpi-build.c |   2 +-
hw/riscv/virt.c            | 109 ++++++++++++-------------------------
3 files changed, 37 insertions(+), 78 deletions(-)
[PATCH 0/7] hw/riscv: fix leak, add more g_autofree
Posted by Daniel Henrique Barboza 10 months, 1 week ago
Hi,

First patch fixes a leak found when using Valgrind. The root cause is a
missing g_free() in a string. 

In fact, I found while doing reviews that we keep repeating the same
pattern:

====
char *name;
name = g_strdup_printf(...);
(...)
g_free(name);
====

With this in mind, I ended up making this rather trivial series to
introduce more string/array autocleaning in the 'virt' machine code. The
advantage of doing 'g_autofree' is that we'll guarantee that we'll clean
ourselves up when the variable goes out of scope, avoiding leaks like
the one patch 1 fixes. We want to enforce this autoclean style in
reviews, and for that we need to get rid of at least some of the uses we
do it right now.

I didn't bother changing the 'spike' and the 'sifive' boards for now
because the bulk of new patches is done on top of the 'virt' machine,
so it's more important to tidy this board first.


Daniel Henrique Barboza (7):
  hw/riscv/virt-acpi-build.c: fix leak in build_rhct()
  hw/riscv/numa.c: use g_autofree in socket_fdt_write_distance_matrix()
  hw/riscv/virt.c: use g_autofree in create_fdt_socket_cpus()
  hw/riscv/virt.c: use g_autofree in create_fdt_sockets()
  hw/riscv/virt.c: use g_autofree in create_fdt_virtio()
  hw/riscv/virt.c: use g_autofree in virt_machine_init()
  hw/riscv/virt.c: use g_autofree in create_fdt_*

 hw/riscv/numa.c            |   4 +-
 hw/riscv/virt-acpi-build.c |   2 +-
 hw/riscv/virt.c            | 109 ++++++++++++-------------------------
 3 files changed, 37 insertions(+), 78 deletions(-)

-- 
2.43.0
Re: [PATCH 0/7] hw/riscv: fix leak, add more g_autofree
Posted by Alistair Francis 9 months, 3 weeks ago
On Tue, Jan 23, 2024 at 9:39 AM Daniel Henrique Barboza
<dbarboza@ventanamicro.com> wrote:
>
> Hi,
>
> First patch fixes a leak found when using Valgrind. The root cause is a
> missing g_free() in a string.
>
> In fact, I found while doing reviews that we keep repeating the same
> pattern:
>
> ====
> char *name;
> name = g_strdup_printf(...);
> (...)
> g_free(name);
> ====
>
> With this in mind, I ended up making this rather trivial series to
> introduce more string/array autocleaning in the 'virt' machine code. The
> advantage of doing 'g_autofree' is that we'll guarantee that we'll clean
> ourselves up when the variable goes out of scope, avoiding leaks like
> the one patch 1 fixes. We want to enforce this autoclean style in
> reviews, and for that we need to get rid of at least some of the uses we
> do it right now.
>
> I didn't bother changing the 'spike' and the 'sifive' boards for now
> because the bulk of new patches is done on top of the 'virt' machine,
> so it's more important to tidy this board first.
>
>
> Daniel Henrique Barboza (7):
>   hw/riscv/virt-acpi-build.c: fix leak in build_rhct()
>   hw/riscv/numa.c: use g_autofree in socket_fdt_write_distance_matrix()
>   hw/riscv/virt.c: use g_autofree in create_fdt_socket_cpus()
>   hw/riscv/virt.c: use g_autofree in create_fdt_sockets()
>   hw/riscv/virt.c: use g_autofree in create_fdt_virtio()
>   hw/riscv/virt.c: use g_autofree in virt_machine_init()
>   hw/riscv/virt.c: use g_autofree in create_fdt_*

Thanks!

Applied to riscv-to-apply.next

Alistair

>
>  hw/riscv/numa.c            |   4 +-
>  hw/riscv/virt-acpi-build.c |   2 +-
>  hw/riscv/virt.c            | 109 ++++++++++++-------------------------
>  3 files changed, 37 insertions(+), 78 deletions(-)
>
> --
> 2.43.0
>
>