[libvirt PATCH] util: fix double destroy / missing unref of GSource

Daniel P. Berrangé posted 1 patch 2 years ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20220426142651.714324-1-berrange@redhat.com
src/util/vireventglib.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[libvirt PATCH] util: fix double destroy / missing unref of GSource
Posted by Daniel P. Berrangé 2 years ago
A leak of the GSource was introduced in

  commit 87a43a907f0ad4897a28ad7c216bc70f37270b93
  Author: Michal Prívozník <mprivozn@redhat.com>
  Date:   Fri Jan 28 18:42:45 2022 +0100

    lib: Use g_clear_pointer() more

As it mistakenly replaced the g_vir_source_unref call with a second
call to g_source_destroy.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 src/util/vireventglib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/util/vireventglib.c b/src/util/vireventglib.c
index fc04d8f712..3cc42597fd 100644
--- a/src/util/vireventglib.c
+++ b/src/util/vireventglib.c
@@ -227,7 +227,7 @@ virEventGLibHandleUpdate(int watch,
             goto cleanup;
 
         VIR_DEBUG("Removed old handle source=%p", data->source);
-        g_source_destroy(data->source);
+        vir_g_source_unref(data->source, NULL);
         g_clear_pointer(&data->source, g_source_destroy);
         data->events = 0;
     }
-- 
2.35.1

Re: [libvirt PATCH] util: fix double destroy / missing unref of GSource
Posted by Michal Prívozník 2 years ago
On 4/26/22 16:26, Daniel P. Berrangé wrote:
> A leak of the GSource was introduced in
> 
>   commit 87a43a907f0ad4897a28ad7c216bc70f37270b93
>   Author: Michal Prívozník <mprivozn@redhat.com>
>   Date:   Fri Jan 28 18:42:45 2022 +0100
> 
>     lib: Use g_clear_pointer() more
> 
> As it mistakenly replaced the g_vir_source_unref call with a second
> call to g_source_destroy.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  src/util/vireventglib.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/util/vireventglib.c b/src/util/vireventglib.c
> index fc04d8f712..3cc42597fd 100644
> --- a/src/util/vireventglib.c
> +++ b/src/util/vireventglib.c
> @@ -227,7 +227,7 @@ virEventGLibHandleUpdate(int watch,
>              goto cleanup;
>  
>          VIR_DEBUG("Removed old handle source=%p", data->source);
> -        g_source_destroy(data->source);
> +        vir_g_source_unref(data->source, NULL);
>          g_clear_pointer(&data->source, g_source_destroy);
>          data->events = 0;
>      }

Ooops,

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal