qga-win: Free GMatchInfo properly
PATCH 1/1 qga-win: Free GMatchInfo properly
The g_regex_match function creates match_info even if it returns FALSE. So we should always call g_match_info_free.
--- qga/commands-win32.c | 1 + 1 file changed, 1 insertion(+)
qga/commands-win32.c +1 -0
@@ -2497,6 +2497,7 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp)GMatchInfo *match_info;GuestDeviceIdPCI *id;if (!g_regex_match (device_pci_re, hw_ids[j],0 , &match_info)) { +g_match_info_free (match_info);continue ; } skip = false;
Signature · 1 line
2.25.1
Hi
Quoted 13 lines · Kostiantyn Kostiuk
The
g_regex_matchfunction createsmatch_infoeven if it returns FALSE. So we should always callg_match_info_free.Signed-off-by Kostiantyn Kostiuk <[email protected]>--- qga/commands-win32.c | 1 + 1 file changed, 1 insertion(+)qga/commands-win32.c +0
-0
qga/commands-win32.c GuestDeviceInfoList *qmp_guest_get_devices(Error · line 2499
Quoted 3 lines
qga/commands-win32.c +0
-0@@ -2497,6 +2497,7 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp)GMatchInfo *match_info;
What about using g_autoptr instead?
GuestDeviceIdPCI *id;
Quoted 11 lines
qga/commands-win32.c +1
-0if (!g_regex_match (device_pci_re, hw_ids[j],0 , &match_info)) { +g_match_info_free (match_info);continue ;} skip = false;--
2.25.1
Signature · 1 line
Marc-André Lureau
Hi All,
For freeing GMatchInfo struct, a special function is required. I'm not sure is it possible to use g_autoptr in this case or no.
In GLib example
https://developer.gnome.org/glib/stable/glib-Perl-compatible-regular-expressions.html#g-regex-match,g_match_info_free is used directly.
Best wishes,
Kostiantyn Kostiuk
Quoted 40 lines · Marc-André Lureau
Hi
Quoted 13 lines · Kostiantyn Kostiuk
The
g_regex_matchfunction createsmatch_infoeven if it returns FALSE. So we should always callg_match_info_free.Signed-off-by Kostiantyn Kostiuk <[email protected]>--- qga/commands-win32.c | 1 + 1 file changed, 1 insertion(+)qga/commands-win32.c +0
-0qga/commands-win32.c GuestDeviceInfoList *qmp_guest_get_devices(Error · line 2499
Quoted 3 lines
qga/commands-win32.c +0
-0@@ -2497,6 +2497,7 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp)GMatchInfo *match_info;What about using
g_autoptrinstead?GuestDeviceIdPCI *id;Quoted 11 lines
qga/commands-win32.c +1
-0if (!g_regex_match (device_pci_re, hw_ids[j],0 , &match_info)) { +g_match_info_free (match_info);continue ;} skip = false;--
2.25.1--
Marc-André Lureau
Quoted 7 lines · Konstantin Kostiuk
Hi All,
For freeing GMatchInfo struct, a special function is required. I'm not sure is it possible to use
g_autoptrin this case or no.
In GLib example
https://developer.gnome.org/glib/stable/glib-Perl-compatible-regular-expressions.html#g-regex-match,g_match_info_freeis used directly.
That is fine - g_autoptr calls the required deallocation function that was previously registered. This is different from g_autofree which merely calls g_free.
We can see GMatchInfo is configured to call g_match_info_free:
$ grep GMatchIn /usr/include/glib-2.0/glib/*.h /usr/include/glib-2.0/glib/glib-autocleanups.h:G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMatchInfo, g_match_info_unref)
Regards,
Daniel
Signature · 3 lines
|: 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 :|
Thanks, Daniel!
A new patch was sent.
Best wishes,
Kostiantyn Kostiuk
Quoted 34 lines · Daniel P. Berrangé
Quoted 3 lines · Konstantin Kostiuk
Hi All,
For freeing GMatchInfo struct, a special function is required. I'm not
sure is
Quoted 3 lines
it possible to use
g_autoptrin this case or no.
In GLib examplehttps://developer.gnome.org/glib/stable/glib-Perl-compatible-regular-expressions.html#g-regex-match
,Quoted 1 line
g_match_info_freeis used directly.That is fine -
g_autoptrcalls the required deallocation function that was previously registered. This is different fromg_autofreewhich merely callsg_free.We can see GMatchInfo is configured to call
g_match_info_free:$ grep GMatchIn /usr/include/glib-2.0/glib/*.h /usr/include/glib-2.0/glib/glib-autocleanups.h:G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMatchInfo, g_match_info_unref)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 :|