All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] qga-win: Free GMatchInfo properly
@ 2021-06-10 14:38 Kostiantyn Kostiuk
  2021-06-10 14:41 ` Marc-André Lureau
  0 siblings, 1 reply; 5+ messages in thread
From: Kostiantyn Kostiuk @ 2021-06-10 14:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael Roth

The g_regex_match function creates match_info even if it
returns FALSE. So we should always call g_match_info_free.

Signed-off-by: Kostiantyn Kostiuk <konstantin@daynix.com>
---
 qga/commands-win32.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 300b87c859..e8bc3df306 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -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;
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] qga-win: Free GMatchInfo properly
  2021-06-10 14:38 [PATCH] qga-win: Free GMatchInfo properly Kostiantyn Kostiuk
@ 2021-06-10 14:41 ` Marc-André Lureau
  2021-06-10 14:53   ` Konstantin Kostiuk
  0 siblings, 1 reply; 5+ messages in thread
From: Marc-André Lureau @ 2021-06-10 14:41 UTC (permalink / raw)
  To: Kostiantyn Kostiuk; +Cc: QEMU, Michael Roth

[-- Attachment #1: Type: text/plain, Size: 982 bytes --]

Hi

On Thu, Jun 10, 2021 at 6:38 PM Kostiantyn Kostiuk <konstantin@daynix.com>
wrote:

> The g_regex_match function creates match_info even if it
> returns FALSE. So we should always call g_match_info_free.
>
> Signed-off-by: Kostiantyn Kostiuk <konstantin@daynix.com>
> ---
>  qga/commands-win32.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> index 300b87c859..e8bc3df306 100644
> --- a/qga/commands-win32.c
> +++ b/qga/commands-win32.c
> @@ -2497,6 +2497,7 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error
> **errp)
>              GMatchInfo *match_info;
>

What about using g_autoptr instead?

             GuestDeviceIdPCI *id;
>              if (!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

[-- Attachment #2: Type: text/html, Size: 1686 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] qga-win: Free GMatchInfo properly
  2021-06-10 14:41 ` Marc-André Lureau
@ 2021-06-10 14:53   ` Konstantin Kostiuk
  2021-06-10 15:23     ` Daniel P. Berrangé
  0 siblings, 1 reply; 5+ messages in thread
From: Konstantin Kostiuk @ 2021-06-10 14:53 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: QEMU, Michael Roth

[-- Attachment #1: Type: text/plain, Size: 1459 bytes --]

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


On Thu, Jun 10, 2021 at 5:41 PM Marc-André Lureau <
marcandre.lureau@gmail.com> wrote:

> Hi
>
> On Thu, Jun 10, 2021 at 6:38 PM Kostiantyn Kostiuk <konstantin@daynix.com>
> wrote:
>
>> The g_regex_match function creates match_info even if it
>> returns FALSE. So we should always call g_match_info_free.
>>
>> Signed-off-by: Kostiantyn Kostiuk <konstantin@daynix.com>
>> ---
>>  qga/commands-win32.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/qga/commands-win32.c b/qga/commands-win32.c
>> index 300b87c859..e8bc3df306 100644
>> --- a/qga/commands-win32.c
>> +++ b/qga/commands-win32.c
>> @@ -2497,6 +2497,7 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error
>> **errp)
>>              GMatchInfo *match_info;
>>
>
> What about using g_autoptr instead?
>
>              GuestDeviceIdPCI *id;
>>              if (!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
>

[-- Attachment #2: Type: text/html, Size: 2741 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] qga-win: Free GMatchInfo properly
  2021-06-10 14:53   ` Konstantin Kostiuk
@ 2021-06-10 15:23     ` Daniel P. Berrangé
  2021-06-10 15:59       ` Konstantin Kostiuk
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel P. Berrangé @ 2021-06-10 15:23 UTC (permalink / raw)
  To: Konstantin Kostiuk; +Cc: Marc-André Lureau, QEMU, Michael Roth

On Thu, Jun 10, 2021 at 05:53:35PM +0300, Konstantin Kostiuk wrote:
> 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.

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
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] qga-win: Free GMatchInfo properly
  2021-06-10 15:23     ` Daniel P. Berrangé
@ 2021-06-10 15:59       ` Konstantin Kostiuk
  0 siblings, 0 replies; 5+ messages in thread
From: Konstantin Kostiuk @ 2021-06-10 15:59 UTC (permalink / raw)
  To: Daniel P. Berrangé; +Cc: Marc-André Lureau, QEMU, Michael Roth

[-- Attachment #1: Type: text/plain, Size: 1258 bytes --]

Thanks, Daniel!

A new patch was sent.

Best wishes,
Kostiantyn Kostiuk


On Thu, Jun 10, 2021 at 6:23 PM Daniel P. Berrangé <berrange@redhat.com>
wrote:

> On Thu, Jun 10, 2021 at 05:53:35PM +0300, Konstantin Kostiuk wrote:
> > 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.
>
> 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
> --
> |: 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 :|
>
>

[-- Attachment #2: Type: text/html, Size: 2434 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-10 16:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-10 14:38 [PATCH] qga-win: Free GMatchInfo properly Kostiantyn Kostiuk
2021-06-10 14:41 ` Marc-André Lureau
2021-06-10 14:53   ` Konstantin Kostiuk
2021-06-10 15:23     ` Daniel P. Berrangé
2021-06-10 15:59       ` Konstantin Kostiuk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.