qga-win: Free GMatchInfo properly
PATCH v2 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. A better solution is using g_autoptr for match_info variable.
--- qga/commands-win32.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
qga/commands-win32.c +1 -2
@@ -2494,7 +2494,7 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp)continue ; }for (j =0 ; hw_ids[j] !=NULL ; j++) { -GMatchInfo *match_info; +g_autoptr (GMatchInfo) match_info;GuestDeviceIdPCI *id;if (!g_regex_match (device_pci_re, hw_ids[j],0 , &match_info)) {continue ;
@@ -2511,7 +2511,6 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) id->vendor_id =g_ascii_strtoull (vendor_id,NULL ,16 ); id->device_id =g_ascii_strtoull (device_id,NULL ,16 ); -g_match_info_free (match_info);break ; }if (skip) {
Signature · 1 line
2.25.1
Quoted 8 lines · Kostiantyn Kostiuk
The
g_regex_matchfunction createsmatch_infoeven if it returns FALSE. So we should always callg_match_info_free. A better solution is usingg_autoptrformatch_infovariable.Signed-off-by Kostiantyn Kostiuk <[email protected]>--- qga/commands-win32.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 14 lines · Kostiantyn Kostiuk
The
g_regex_matchfunction createsmatch_infoeven if it returns FALSE. So we should always callg_match_info_free. A better solution is usingg_autoptrformatch_infovariable.Signed-off-by Kostiantyn Kostiuk <[email protected]>--- qga/commands-win32.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)qga/commands-win32.c +0
-0
qga/commands-win32.c GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) · line 2497
Quoted 5 lines
qga/commands-win32.c +1
-1@@ -2494,7 +2494,7 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp)continue ; }for (j =0 ; hw_ids[j] !=NULL ; j++) { -GMatchInfo *match_info; +g_autoptr (GMatchInfo) match_info;
This should be initialized to NULL otherwise...
qga/commands-win32.c GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) · line 2500
Quoted 3 lines
qga/commands-win32.c +0
-0GuestDeviceIdPCI *id;if (!g_regex_match (device_pci_re, hw_ids[j],0 , &match_info)) {continue ;
this continue will trigger freeing of unintialized memory
Essentially all g_auto* variables should be init to NULL at all times, even if it currently looks harmless.
qga/commands-win32.c GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) · line 2516
Quoted 8 lines
qga/commands-win32.c +0
-1@@ -2511,7 +2511,6 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) id->vendor_id =g_ascii_strtoull (vendor_id,NULL ,16 ); id->device_id =g_ascii_strtoull (device_id,NULL ,16 ); -g_match_info_free (match_info);break ; }if (skip) {
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 :|
Quoted 22 lines · Daniel P. Berrangé
qga/commands-win32.c GuestDeviceInfoList *qmp_guest_get_devices(Error
Quoted 14 lines · Kostiantyn Kostiuk
The
g_regex_matchfunction createsmatch_infoeven if it returns FALSE. So we should always callg_match_info_free. A better solution is usingg_autoptrformatch_infovariable.Signed-off-by Kostiantyn Kostiuk <[email protected]>--- qga/commands-win32.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)qga/commands-win32.c +0
-0@@ -2494,7 +2494,7 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error**errp)
qga/commands-win32.c GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) · line 2497
Quoted 5 lines
qga/commands-win32.c +1
-1continue ; }for (j =0 ; hw_ids[j] !=NULL ; j++) { -GMatchInfo *match_info; +g_autoptr (GMatchInfo) match_info;
Quoted 9 lines
This should be initialized to NULL otherwise...
qga/commands-win32.c GuestDeviceInfoList *qmp_guest_get_devices(Error · line 2499
Quoted 2 lines
qga/commands-win32.c +0
-0GuestDeviceIdPCI *id; if (!g_regex_match(device_pci_re, hw_ids[j], 0,
&match_info)) {qga/commands-win32.c GuestDeviceInfoList *qmp_guest_get_devices(Error · line 2500
Quoted 1 line
qga/commands-win32.c +0
-0continue ;this continue will trigger freeing of unintialized memory
But we always call match_info, so match_info is always initialized. The g_regex_match function creates match_info even if it returns FALSE.
Quoted 14 lines
Essentially all g_auto* variables should be init to NULL at all times, even if it currently looks harmless.
qga/commands-win32.c GuestDeviceInfoList *qmp_guest_get_devices(Error
Quoted 1 line
qga/commands-win32.c +0
-0@@ -2511,7 +2511,6 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error**errp)
qga/commands-win32.c GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) · line 2516
Quoted 7 lines
qga/commands-win32.c +0
-1id->vendor_id =g_ascii_strtoull (vendor_id,NULL ,16 ); id->device_id =g_ascii_strtoull (device_id,NULL ,16 ); -g_match_info_free (match_info);break ; }if (skip) {
Quoted 11 lines
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 :|
Best wishes,
Kostiantyn Kostiuk
Daniel P. Berrangé
Reviewed-byQuoted 29 lines · Konstantin Kostiuk
Quoted 26 lines · Daniel P. Berrangé
qga/commands-win32.c GuestDeviceInfoList *qmp_guest_get_devices(Error
Quoted 14 lines · Kostiantyn Kostiuk
The
g_regex_matchfunction createsmatch_infoeven if it returns FALSE. So we should always callg_match_info_free. A better solution is usingg_autoptrformatch_infovariable.Signed-off-by Kostiantyn Kostiuk <[email protected]>--- qga/commands-win32.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)qga/commands-win32.c +0
-0@@ -2494,7 +2494,7 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error**errp)
qga/commands-win32.c GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) · line 2497
Quoted 5 lines
qga/commands-win32.c +1
-1continue ; }for (j =0 ; hw_ids[j] !=NULL ; j++) { -GMatchInfo *match_info; +g_autoptr (GMatchInfo) match_info;This should be initialized to NULL otherwise...
Quoted 2 lines
qga/commands-win32.c +0
-0GuestDeviceIdPCI *id; if (!g_regex_match(device_pci_re, hw_ids[j], 0,
Quoted 8 lines
Quoted 5 lines
&match_info)) {qga/commands-win32.c GuestDeviceInfoList *qmp_guest_get_devices(Error · line 2500
Quoted 1 line
qga/commands-win32.c +0
-0continue ;this continue will trigger freeing of unintialized memory
But we always call
match_info, somatch_infois always initialized. Theg_regex_matchfunction createsmatch_infoeven if it returns FALSE.
Opps, yes, you are right.
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 :|
CC Michael Roth
Quoted 56 lines · Daniel P. Berrangé
Quoted 13 lines · Konstantin Kostiuk
Quoted 10 lines · Daniel P. Berrangé
Quoted 9 lines · Kostiantyn Kostiuk
The
g_regex_matchfunction createsmatch_infoeven if it returns FALSE. So we should always callg_match_info_free. A better solution is usingg_autoptrformatch_infovariable.Signed-off-by Kostiantyn Kostiuk <[email protected]>--- qga/commands-win32.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)Quoted 5 lines
Quoted 5 lines
qga/commands-win32.c GuestDeviceInfoList
Quoted 5 lines
qga/commands-win32.c +0
-0@@ -2494,7 +2494,7 @@ GuestDeviceInfoList*qmp_guest_get_devices(Error
Quoted 11 lines
Quoted 11 lines
**errp)
qga/commands-win32.c GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) · line 2497
Quoted 5 lines
qga/commands-win32.c +1
-1continue ; }for (j =0 ; hw_ids[j] !=NULL ; j++) { -GMatchInfo *match_info; +g_autoptr (GMatchInfo) match_info;This should be initialized to NULL otherwise...
Quoted 2 lines
qga/commands-win32.c +0
-0GuestDeviceIdPCI *id; if (!g_regex_match(device_pci_re, hw_ids[j], 0,Quoted 8 lines
Quoted 5 lines
&match_info)) {qga/commands-win32.c GuestDeviceInfoList · line 2500
Quoted 1 line
qga/commands-win32.c +0
-0continue ;this continue will trigger freeing of unintialized memory
But we always call
match_info, somatch_infois always initialized. Theg_regex_matchfunction createsmatch_infoeven if it returns FALSE.Opps, yes, you are right.
Reviewed-by Daniel P. Berrangé <[email protected]>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 :|
ping
Quoted 62 lines · Konstantin Kostiuk
CC Michael Roth
Quoted 57 lines · Daniel P. Berrangé
Quoted 14 lines · Konstantin Kostiuk
On Thu, Jun 10, 2021 at 7:02 PM Daniel P. Berrangé <[email protected]
Quoted 10 lines · wrote:
Quoted 9 lines · Kostiantyn Kostiuk
The
g_regex_matchfunction createsmatch_infoeven if it returns FALSE. So we should always callg_match_info_free. A better solution is usingg_autoptrformatch_infovariable.Signed-off-by Kostiantyn Kostiuk <[email protected]>--- qga/commands-win32.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)Quoted 5 lines
Quoted 5 lines
qga/commands-win32.c GuestDeviceInfoList
Quoted 5 lines
qga/commands-win32.c +0
-0@@ -2494,7 +2494,7 @@ GuestDeviceInfoList*qmp_guest_get_devices(Error
Quoted 11 lines
Quoted 11 lines
**errp)
qga/commands-win32.c GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) · line 2497
Quoted 5 lines
qga/commands-win32.c +1
-1continue ; }for (j =0 ; hw_ids[j] !=NULL ; j++) { -GMatchInfo *match_info; +g_autoptr (GMatchInfo) match_info;This should be initialized to NULL otherwise...
Quoted 2 lines
qga/commands-win32.c +0
-0GuestDeviceIdPCI *id; if (!g_regex_match(device_pci_re, hw_ids[j], 0,Quoted 8 lines
Quoted 5 lines
&match_info)) {qga/commands-win32.c GuestDeviceInfoList · line 2500
Quoted 1 line
qga/commands-win32.c +0
-0continue ;this continue will trigger freeing of unintialized memory
But we always call
match_info, somatch_infois always initialized. Theg_regex_matchfunction createsmatch_infoeven if it returns FALSE.Opps, yes, you are right.
Reviewed-by Daniel P. Berrangé <[email protected]>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 :|
Still candidate for 6.1.
Quoted 73 lines · Konstantin Kostiuk
ping
On Wed, Jul 14, 2021 at 10:26 AM Konstantin Kostiuk <[email protected] <mailto:[email protected]>> wrote:
CC Michael Roth On Thu, Jun 10, 2021 at 7:14 PM Daniel P. Berrangé <[email protected] <mailto:[email protected]>> wrote: On Thu, Jun 10, 2021 at 07:08:36PM +0300, Konstantin Kostiuk wrote: > On Thu, Jun 10, 2021 at 7:02 PM Daniel P. Berrangé <[email protected] <mailto:[email protected]>> > wrote: > > > On Thu, Jun 10, 2021 at 06:58:11PM +0300, Kostiantyn Kostiuk wrote: > > > The g_regex_match function creates match_info even if it > > > returns FALSE. So we should always call g_match_info_free. > > > A better solution is using g_autoptr for match_info variable. > > > > > > Signed-off-by: Kostiantyn Kostiuk <[email protected] <mailto:[email protected]>> > > > --- > > > qga/commands-win32.c | 3 +-- > > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > > > diff --git a/qga/commands-win32.c b/qga/commands-win32.c > > > index 300b87c859..785a5cc6b2 100644 > > > --- a/qga/commands-win32.c > > > +++ b/qga/commands-win32.c > > > @@ -2494,7 +2494,7 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error > > **errp) > > > continue; > > > } > > > for (j = 0; hw_ids[j] != NULL; j++) { > > > - GMatchInfo *match_info; > > > + g_autoptr(GMatchInfo) match_info; > > > > This should be initialized to NULL otherwise... > > > > > GuestDeviceIdPCI *id; > > > if (!g_regex_match(device_pci_re, hw_ids[j], 0, > > &match_info)) { > > > continue; > > > > this continue will trigger freeing of unintialized memory > > > > But we always call match_info, so match_info is always initialized. > The g_regex_match function creates match_info even if it returns FALSE. Opps, yes, you are right. Reviewed-by: Daniel P. Berrangé <[email protected] <mailto:[email protected]>> Regards, Daniel -- |: https://berrange.com <https://berrange.com> -o- https://www.flickr.com/photos/dberrange <https://www.flickr.com/photos/dberrange> :| |: https://libvirt.org <https://libvirt.org> -o- https://fstop138.berrange.com <https://fstop138.berrange.com> :| |: https://entangle-photo.org <https://entangle-photo.org> -o- https://www.instagram.com/dberrange <https://www.instagram.com/dberrange> :|