[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2] hw/acpi: Fix GPtrArray memory leak in crs_range_merge
From: |
Ani Sinha |
Subject: |
Re: [PATCH v2] hw/acpi: Fix GPtrArray memory leak in crs_range_merge |
Date: |
Fri, 13 Jun 2025 15:46:35 +0530 |
> On 13 Jun 2025, at 2:35 PM, Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> On Fri, Jun 13, 2025 at 04:51:10PM +0800, Li Zhijian wrote:
>> This leak was detected by the valgrind.
>>
>> The crs_range_merge() function unconditionally allocated a GPtrArray
>> 'even when range->len was zero, causing an early return without freeing
>> the allocated array. This resulted in a memory leak when an empty range
>> was processed.
>>
>> Instead of moving the allocation after the check (as previously attempted),
>> use g_autoptr for automatic cleanup. This ensures the array is freed even
>> on early returns, and also removes the need for the explicit free at the
>> end of the function.
>>
>> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
>> ---
>
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Ani Sinha <anisinha@redhat.com>
>
>
> 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 :|