context: Fix invalid accesses to GUsbContext if USB is missing

When USB cannot be initialised (inside the flatpak build environment),
then we would have invalid accesses to the NULL pointer. Fix those.
This commit is contained in:
Benjamin Berg 2020-09-03 09:06:37 +02:00
parent c85f385191
commit 596d22a449

View file

@ -210,7 +210,8 @@ fp_context_finalize (GObject *object)
g_clear_object (&priv->cancellable);
g_clear_pointer (&priv->drivers, g_array_unref);
g_object_run_dispose (G_OBJECT (priv->usb_ctx));
if (priv->usb_ctx)
g_object_run_dispose (G_OBJECT (priv->usb_ctx));
g_clear_object (&priv->usb_ctx);
G_OBJECT_CLASS (fp_context_parent_class)->finalize (object);
@ -342,7 +343,8 @@ fp_context_enumerate (FpContext *context)
priv->enumerated = TRUE;
/* USB devices are handled from callbacks */
g_usb_context_enumerate (priv->usb_ctx);
if (priv->usb_ctx)
g_usb_context_enumerate (priv->usb_ctx);
/* Handle Virtual devices based on environment variables */
for (i = 0; i < priv->drivers->len; i++)