Re: [PATCH] tests: fix test-cutils leaks

2022-06-21 Thread Peter Maydell
On Tue, 21 Jun 2022 at 12:50, Marc-André Lureau
 wrote:
>
> Hi
>
> On Tue, Jun 21, 2022 at 3:46 PM Peter Maydell  
> wrote:
>>
>> On Tue, 21 Jun 2022 at 09:36,  wrote:
>> >
>> > From: Marc-André Lureau 
>> >
>> > Reported by ASAN.
>> >
>> > Fixes commit cfb34489 ("cutils: add functions for IEC and SI prefixes").
>> >
>> > Signed-off-by: Marc-André Lureau 
>>
>> g_autofree would be neater, but this works, so:
>> Reviewed-by: Peter Maydell 
>>
>
> sadly, not really, since you have to call g_free() before new assignments... 
> (yes it makes me sad too :)

You could split it up into multiple variables:

 g_autofree char *s1 = freq_to_str(999);
 g_autofree char *s2 = freq_to_str(1000);
 g_autofree char *s3 = freq_to_str(1010);

 g_assert_cmpstr(s1, ==, "999 Hz");
 g_assert_cmpstr(s2, ==, "1 KHz");
 g_assert_cmpstr(s3, ==, "1.01 KHz");

-- PMM



Re: [PATCH] tests: fix test-cutils leaks

2022-06-21 Thread Marc-André Lureau
Hi

On Tue, Jun 21, 2022 at 3:46 PM Peter Maydell 
wrote:

> On Tue, 21 Jun 2022 at 09:36,  wrote:
> >
> > From: Marc-André Lureau 
> >
> > Reported by ASAN.
> >
> > Fixes commit cfb34489 ("cutils: add functions for IEC and SI prefixes").
> >
> > Signed-off-by: Marc-André Lureau 
>
> g_autofree would be neater, but this works, so:
> Reviewed-by: Peter Maydell 
>
>
sadly, not really, since you have to call g_free() before new
assignments... (yes it makes me sad too :)


-- 
Marc-André Lureau


Re: [PATCH] tests: fix test-cutils leaks

2022-06-21 Thread Peter Maydell
On Tue, 21 Jun 2022 at 09:36,  wrote:
>
> From: Marc-André Lureau 
>
> Reported by ASAN.
>
> Fixes commit cfb34489 ("cutils: add functions for IEC and SI prefixes").
>
> Signed-off-by: Marc-André Lureau 

g_autofree would be neater, but this works, so:
Reviewed-by: Peter Maydell 

thanks
-- PMM