From 2e65a351fe334417ca97973365f711a2a4eb0875 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Wed, 28 Oct 2009 22:16:09 +0100 Subject: [PATCH] =?utf8?q?Bug=2024778=20=E2=80=94=20throw=5Ferror()=20segf?= =?utf8?q?aults=20for=20daemon-internally=20called=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Some functions like devkit_disks_device_drive_ata_smart_refresh_data() are used internally by the daemon, in which case the DBusGMethodInvocation context is NULL. If these methods throw an error (observed on "daemon is inhibited"), this NULL context is propagated all the way down to throw_error, which previously tried to call dbus_g_method_return_error() with a NULL context; there is no D-Bus method call to terminate, so this caused a segfault. Change throw_error() to just use g_warning() in this case, so that the error appears on the daemon's stderr. This makes it generally safe to internally call D-Bus exported methods. Signed-off-by: David Zeuthen --- src/devkit-disks-daemon.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/devkit-disks-daemon.c b/src/devkit-disks-daemon.c index 6acd387..cc81e1e 100644 --- a/src/devkit-disks-daemon.c +++ b/src/devkit-disks-daemon.c @@ -1110,11 +1110,16 @@ throw_error (DBusGMethodInvocation *context, int error_code, const char *format, message = g_strdup_vprintf (format, args); va_end (args); - error = g_error_new (DEVKIT_DISKS_ERROR, - error_code, - "%s", message); - dbus_g_method_return_error (context, error); - g_error_free (error); + if (context != NULL) { + error = g_error_new (DEVKIT_DISKS_ERROR, + error_code, + "%s", message); + dbus_g_method_return_error (context, error); + g_error_free (error); + } else { + /* error from a daemon-internal method call */ + g_warning ("%s", message); + } g_free (message); return TRUE; } -- 2.7.4