On Wed, 22 Oct 2025 at 13:39, Daniel Henrique Barboza
<[email protected]> wrote:
> On 10/22/25 8:59 AM, Peter Maydell wrote:
> > g_autofree frees with g_free(), which isn't the right thing for
> > freeing an array of pointers. To do autofree here we need
> >
> >   g_auto(GStrv) reg_name = g_strsplit(...);
> >
> > (GStrv is the glib type for gchar**; the headers give it an
> > auto-free mechanism that calls g_strfreev().)
>
> I saw some instances of "g_autofree char **" and figured that it was ok to use
> g_autofree in this case too (just git grepping, didn't dive deeper to figure
> out context and so on).

There might be some lurking bugs here -- it's an easy
mistake to make. I did a quick audit on the results of
 git grep 'g_autofree.*\*\*'

It looks like migration/migration-hmp-cmds.c:hmp_migrate_set_parameter()
does the wrong thing when it calls g_shell_parse_argv(),
because that function documents that the vector should
be freed with g_strfreev().

All the others are OK, because the elements of the
array are either manually dereffed or else remain
the ownership of something else and shouldn't be freed.

The migration one is a recent addition so I'll follow
up to the patch where it got added to the codebase.

thanks
-- PMM

Reply via email to