[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] tests: fix test-cutils leaks
From: |
Peter Maydell |
Subject: |
Re: [PATCH] tests: fix test-cutils leaks |
Date: |
Tue, 21 Jun 2022 12:52:55 +0100 |
On Tue, 21 Jun 2022 at 12:50, Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Tue, Jun 21, 2022 at 3:46 PM Peter Maydell <peter.maydell@linaro.org>
> wrote:
>>
>> On Tue, 21 Jun 2022 at 09:36, <marcandre.lureau@redhat.com> wrote:
>> >
>> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
>> >
>> > Reported by ASAN.
>> >
>> > Fixes commit cfb34489 ("cutils: add functions for IEC and SI prefixes").
>> >
>> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>>
>> g_autofree would be neater, but this works, so:
>> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
>>
>
> 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