[PATCH] qemu_domain: Don't unref NULL hash table in qemuDomainRefreshStatsSchema()

Michal Privoznik posted 1 patch 1 year, 3 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/4d1500dbecfe8b8e28dd24d075864143cbc867d9.1674736875.git.mprivozn@redhat.com
src/qemu/qemu_domain.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] qemu_domain: Don't unref NULL hash table in qemuDomainRefreshStatsSchema()
Posted by Michal Privoznik 1 year, 3 months ago
The g_hash_table_unref() function does not accept NULL. Passing
NULL results in a glib warning being triggered. Check whether the
hash table is not NULL and unref it only then.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_domain.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index b6ad118f1f..881c88d54c 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -11923,7 +11923,8 @@ qemuDomainRefreshStatsSchema(virDomainObj *dom)
     if (!schema)
         return -1;
 
-    g_hash_table_unref(priv->statsSchema);
+    if (priv->statsSchema)
+        g_hash_table_unref(priv->statsSchema);
     priv->statsSchema = schema;
 
     return 0;
-- 
2.39.1
Re: [PATCH] qemu_domain: Don't unref NULL hash table in qemuDomainRefreshStatsSchema()
Posted by Ján Tomko 1 year, 3 months ago
On a Thursday in 2023, Michal Privoznik wrote:
>The g_hash_table_unref() function does not accept NULL. Passing
>NULL results in a glib warning being triggered. Check whether the
>hash table is not NULL and unref it only then.
>
>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>---
> src/qemu/qemu_domain.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano