From cd458666a93fe9d07f3718e88f3169f01a11a63e Mon Sep 17 00:00:00 2001
From: Tomas Bzatek <tbzatek@redhat.com>
Date: Fri, 16 Apr 2021 18:36:16 +0200
Subject: [PATCH 7/8] udiskslinuxmdraidobject: Handle source attach failure
gracefully
Only negligible theoretical chance to hit this, reported by Coverity.
---
src/udiskslinuxmdraidobject.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/udiskslinuxmdraidobject.c b/src/udiskslinuxmdraidobject.c
index 20ca89c5..828c7058 100644
--- a/src/udiskslinuxmdraidobject.c
+++ b/src/udiskslinuxmdraidobject.c
@@ -468,7 +468,8 @@ watch_attr (UDisksLinuxDevice *device,
GError *error = NULL;
gchar *path = NULL;
GIOChannel *channel = NULL;
- GSource *ret = NULL;;
+ GSource *ret = NULL;
+ guint source_id;
g_return_val_if_fail (UDISKS_IS_LINUX_DEVICE (device), NULL);
@@ -478,9 +479,14 @@ watch_attr (UDisksLinuxDevice *device,
{
ret = g_io_create_watch (channel, G_IO_ERR);
g_source_set_callback (ret, callback, user_data, NULL);
- g_source_attach (ret, g_main_context_get_thread_default ());
+ source_id = g_source_attach (ret, g_main_context_get_thread_default ());
g_source_unref (ret);
g_io_channel_unref (channel); /* the keeps a reference to this object */
+ if (source_id == 0)
+ {
+ /* something bad happened while attaching the source */
+ ret = NULL;
+ }
}
else
{
--
2.30.2