[PATCH] virGDBusBusInit: Properly check for error when looking up D-Bus address

Michal Privoznik posted 1 patch 3 years, 5 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/7a1fe0c65f6fd4c2ed52e27247558bd652e1ea36.1604669426.git.mprivozn@redhat.com
src/util/virgdbus.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] virGDBusBusInit: Properly check for error when looking up D-Bus address
Posted by Michal Privoznik 3 years, 5 months ago
The virGDBusBusInit is supposed to return a reference to
requested bus type (system/session) or, if non-shared bus is
requested then create a new bus of the type. As an argument, it
gets a double pointer to GError which is passed to all g_dbus_*()
calls which allocate it on failure. Pretty standard approach.
However, since it is a double pointer we must dereference the
first level to see if the value is NULL. IOW:

  if (*error)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/util/virgdbus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/util/virgdbus.c b/src/util/virgdbus.c
index 4360a6acff..19fd7e2fe4 100644
--- a/src/util/virgdbus.c
+++ b/src/util/virgdbus.c
@@ -55,7 +55,7 @@ virGDBusBusInit(GBusType type, GError **error)
         return g_bus_get_sync(type, NULL, error);
     } else {
         address = g_dbus_address_get_for_bus_sync(type, NULL, error);
-        if (error)
+        if (*error)
             return NULL;
         return g_dbus_connection_new_for_address_sync(address,
                                                       G_DBUS_CONNECTION_FLAGS_NONE,
-- 
2.26.2

Re: [PATCH] virGDBusBusInit: Properly check for error when looking up D-Bus address
Posted by Pavel Hrdina 3 years, 5 months ago
On Fri, Nov 06, 2020 at 02:30:26PM +0100, Michal Privoznik wrote:
> The virGDBusBusInit is supposed to return a reference to
> requested bus type (system/session) or, if non-shared bus is
> requested then create a new bus of the type. As an argument, it
> gets a double pointer to GError which is passed to all g_dbus_*()
> calls which allocate it on failure. Pretty standard approach.
> However, since it is a double pointer we must dereference the
> first level to see if the value is NULL. IOW:
> 
>   if (*error)
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/util/virgdbus.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>