23e36b3
diff --git a/src/up-daemon.c b/src/up-daemon.c
23e36b3
index 3fb952b..4884b64 100644
23e36b3
--- a/src/up-daemon.c
23e36b3
+++ b/src/up-daemon.c
23e36b3
@@ -323,6 +323,7 @@ up_daemon_about_to_sleep (UpDaemon *daemon, DBusGMethodInvocation *context)
23e36b3
 				     UP_DAEMON_ERROR_GENERAL,
23e36b3
 				     "Sleep has already been requested and is pending");
23e36b3
 		dbus_g_method_return_error (context, error);
23e36b3
+                g_error_free (error);
23e36b3
 		goto out;
23e36b3
 	}
23e36b3
 
23e36b3
@@ -376,6 +377,7 @@ up_daemon_deferred_sleep_cb (UpDaemonDeferredSleep *sleep)
23e36b3
 				     "Failed to spawn: %s, stdout:%s, stderr:%s", error_local->message, stdout, stderr);
23e36b3
 		g_error_free (error_local);
23e36b3
 		dbus_g_method_return_error (sleep->context, error);
23e36b3
+                g_error_free (error);
23e36b3
 		goto out;
23e36b3
 	}
23e36b3
 
23e36b3
@@ -470,6 +472,7 @@ up_daemon_suspend (UpDaemon *daemon, DBusGMethodInvocation *context)
23e36b3
 				     UP_DAEMON_ERROR_GENERAL,
23e36b3
 				     "No kernel support");
23e36b3
 		dbus_g_method_return_error (context, error);
23e36b3
+                g_error_free (error);
23e36b3
 		goto out;
23e36b3
 	}
23e36b3
 
23e36b3
@@ -477,7 +480,7 @@ up_daemon_suspend (UpDaemon *daemon, DBusGMethodInvocation *context)
23e36b3
 	if (subject == NULL)
23e36b3
 		goto out;
23e36b3
 
23e36b3
-	if (!up_polkit_check_auth (priv->polkit, subject, "org.freedesktop.upower.suspend", context))
a5e7acc
+	if (!up_polkit_check_auth (priv->polkit, subject, "org.freedesktop.upower.suspend", context))
23e36b3
 		goto out;
23e36b3
 
23e36b3
 	/* already requested */
23e36b3
@@ -486,6 +489,7 @@ up_daemon_suspend (UpDaemon *daemon, DBusGMethodInvocation *context)
23e36b3
 				     UP_DAEMON_ERROR_GENERAL,
23e36b3
 				     "Sleep has already been requested and is pending");
23e36b3
 		dbus_g_method_return_error (context, error);
23e36b3
+                g_error_free (error);
23e36b3
 		goto out;
23e36b3
 	}
23e36b3
 
23e36b3
@@ -507,13 +511,21 @@ up_daemon_suspend_allowed (UpDaemon *daemon, DBusGMethodInvocation *context)
23e36b3
 	gboolean ret;
23e36b3
 	PolkitSubject *subject = NULL;
23e36b3
 	UpDaemonPrivate *priv = daemon->priv;
23e36b3
+        GError *error;
23e36b3
 
23e36b3
 	subject = up_polkit_get_subject (priv->polkit, context);
23e36b3
 	if (subject == NULL)
23e36b3
 		goto out;
23e36b3
 
23e36b3
-	ret = up_polkit_is_allowed (priv->polkit, subject, "org.freedesktop.upower.suspend", context);
23e36b3
-	dbus_g_method_return (context, ret);
23e36b3
+        error = NULL;
23e36b3
+	ret = up_polkit_is_allowed (priv->polkit, subject, "org.freedesktop.upower.suspend", &error);
23e36b3
+        if (error) {
23e36b3
+                dbus_g_method_return_error (context, error);
23e36b3
+                g_error_free (error);
23e36b3
+        }
23e36b3
+        else {
23e36b3
+	        dbus_g_method_return (context, ret);
23e36b3
+        }
23e36b3
 
23e36b3
 out:
23e36b3
 	if (subject != NULL)
23e36b3
@@ -563,6 +575,7 @@ up_daemon_hibernate (UpDaemon *daemon, DBusGMethodInvocation *context)
23e36b3
 				     UP_DAEMON_ERROR_GENERAL,
23e36b3
 				     "No kernel support");
23e36b3
 		dbus_g_method_return_error (context, error);
23e36b3
+                g_error_free (error);
23e36b3
 		goto out;
23e36b3
 	}
23e36b3
 
23e36b3
@@ -572,6 +585,7 @@ up_daemon_hibernate (UpDaemon *daemon, DBusGMethodInvocation *context)
23e36b3
 				     UP_DAEMON_ERROR_GENERAL,
23e36b3
 				     "Not enough swap space");
23e36b3
 		dbus_g_method_return_error (context, error);
23e36b3
+                g_error_free (error);
23e36b3
 		goto out;
23e36b3
 	}
23e36b3
 
23e36b3
@@ -582,6 +596,7 @@ up_daemon_hibernate (UpDaemon *daemon, DBusGMethodInvocation *context)
23e36b3
 				     UP_DAEMON_ERROR_GENERAL,
23e36b3
 				     "Swap space is encrypted, use AllowHibernateEncryptedSwap to override");
23e36b3
 		dbus_g_method_return_error (context, error);
23e36b3
+                g_error_free (error);
23e36b3
 		goto out;
23e36b3
 	}
23e36b3
 
23e36b3
@@ -598,6 +613,7 @@ up_daemon_hibernate (UpDaemon *daemon, DBusGMethodInvocation *context)
23e36b3
 				     UP_DAEMON_ERROR_GENERAL,
23e36b3
 				     "Sleep has already been requested and is pending");
23e36b3
 		dbus_g_method_return_error (context, error);
23e36b3
+                g_error_free (error);
23e36b3
 		goto out;
23e36b3
 	}
23e36b3
 
23e36b3
@@ -619,13 +635,21 @@ up_daemon_hibernate_allowed (UpDaemon *daemon, DBusGMethodInvocation *context)
23e36b3
 	gboolean ret;
23e36b3
 	PolkitSubject *subject = NULL;
23e36b3
 	UpDaemonPrivate *priv = daemon->priv;
23e36b3
+        GError *error;
23e36b3
 
23e36b3
 	subject = up_polkit_get_subject (priv->polkit, context);
23e36b3
 	if (subject == NULL)
23e36b3
 		goto out;
23e36b3
 
23e36b3
-	ret = up_polkit_is_allowed (priv->polkit, subject, "org.freedesktop.upower.hibernate", context);
23e36b3
-	dbus_g_method_return (context, ret);
23e36b3
+        error = NULL;
23e36b3
+	ret = up_polkit_is_allowed (priv->polkit, subject, "org.freedesktop.upower.hibernate", &error);
23e36b3
+        if (error) {
23e36b3
+                dbus_g_method_return_error (context, error);
23e36b3
+                g_error_free (error);
23e36b3
+        }
23e36b3
+        else {
23e36b3
+	        dbus_g_method_return (context, ret);
23e36b3
+        }
23e36b3
 
23e36b3
 out:
23e36b3
 	if (subject != NULL)
23e36b3
diff --git a/src/up-polkit.c b/src/up-polkit.c
23e36b3
index 9b86394..bd1e5e0 100644
23e36b3
--- a/src/up-polkit.c
23e36b3
+++ b/src/up-polkit.c
23e36b3
@@ -52,12 +52,19 @@ static gpointer up_polkit_object = NULL;
23e36b3
 PolkitSubject *
23e36b3
 up_polkit_get_subject (UpPolkit *polkit, DBusGMethodInvocation *context)
23e36b3
 {
23e36b3
+        GError *error;
23e36b3
 	const gchar *sender;
23e36b3
 	PolkitSubject *subject;
23e36b3
 
23e36b3
 	sender = dbus_g_method_get_sender (context);
23e36b3
 	subject = polkit_system_bus_name_new (sender);
23e36b3
 
23e36b3
+        if (subject == NULL) {
23e36b3
+		error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "failed to get PolicyKit subject");
23e36b3
+                dbus_g_method_return_error (context, error);
23e36b3
+		g_error_free (error);
23e36b3
+        }
23e36b3
+
23e36b3
 	return subject;
23e36b3
 }
23e36b3
 
23e36b3
@@ -79,9 +86,9 @@ up_polkit_check_auth (UpPolkit *polkit, PolkitSubject *subject, const gchar *act
23e36b3
 							    NULL, &error_local);
23e36b3
 	if (result == NULL) {
23e36b3
 		error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "failed to check authorisation: %s", error_local->message);
23e36b3
-		dbus_g_method_return_error (context, error);
23e36b3
+                dbus_g_method_return_error (context, error);
23e36b3
 		g_error_free (error_local);
23e36b3
-		g_error_free (error);
23e36b3
+                g_error_free (error);
23e36b3
 		goto out;
23e36b3
 	}
23e36b3
 
23e36b3
@@ -90,8 +97,8 @@ up_polkit_check_auth (UpPolkit *polkit, PolkitSubject *subject, const gchar *act
23e36b3
 		ret = TRUE;
23e36b3
 	} else {
23e36b3
 		error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "not authorized");
23e36b3
-		dbus_g_method_return_error (context, error);
23e36b3
-		g_error_free (error);
23e36b3
+                dbus_g_method_return_error (context, error);
23e36b3
+                g_error_free (error);
23e36b3
 	}
23e36b3
 out:
23e36b3
 	if (result != NULL)
23e36b3
@@ -103,10 +110,9 @@ out:
23e36b3
  * up_polkit_is_allowed:
23e36b3
  **/
23e36b3
 gboolean
23e36b3
-up_polkit_is_allowed (UpPolkit *polkit, PolkitSubject *subject, const gchar *action_id, DBusGMethodInvocation *context)
23e36b3
+up_polkit_is_allowed (UpPolkit *polkit, PolkitSubject *subject, const gchar *action_id, GError **error)
23e36b3
 {
23e36b3
 	gboolean ret = FALSE;
23e36b3
-	GError *error;
23e36b3
 	GError *error_local = NULL;
23e36b3
 	PolkitAuthorizationResult *result;
23e36b3
 
23e36b3
@@ -116,10 +122,8 @@ up_polkit_is_allowed (UpPolkit *polkit, PolkitSubject *subject, const gchar *act
23e36b3
 							    POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE,
23e36b3
 							    NULL, &error_local);
23e36b3
 	if (result == NULL) {
23e36b3
-		error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "failed to check authorisation: %s", error_local->message);
23e36b3
-		dbus_g_method_return_error (context, error);
23e36b3
+		g_set_error (error, UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "failed to check authorisation: %s", error_local->message);
23e36b3
 		g_error_free (error_local);
23e36b3
-		g_error_free (error);
23e36b3
 		goto out;
23e36b3
 	}
23e36b3
 
23e36b3
diff --git a/src/up-polkit.h b/src/up-polkit.h
23e36b3
index acee70e..b9abd7e 100644
23e36b3
--- a/src/up-polkit.h
23e36b3
+++ b/src/up-polkit.h
23e36b3
@@ -56,11 +56,11 @@ PolkitSubject	*up_polkit_get_subject		(UpPolkit		*polkit,
23e36b3
 gboolean	 up_polkit_check_auth		(UpPolkit		*polkit,
23e36b3
 						 PolkitSubject		*subject,
23e36b3
 						 const gchar		*action_id,
23e36b3
-						 DBusGMethodInvocation	*context);
23e36b3
+						 DBusGMethodInvocation *context);
23e36b3
 gboolean	 up_polkit_is_allowed		(UpPolkit		*polkit,
23e36b3
 						 PolkitSubject		*subject,
23e36b3
 						 const gchar		*action_id,
23e36b3
-						 DBusGMethodInvocation	*context);
23e36b3
+						 GError               **error);
23e36b3
 gboolean         up_polkit_get_uid		(UpPolkit              *polkit,
23e36b3
                                                  PolkitSubject          *subject,
23e36b3
                                                  uid_t                  *uid);
23e36b3
diff --git a/src/up-qos.c b/src/up-qos.c
23e36b3
index 0ce3eea..b36df3f 100644
23e36b3
--- a/src/up-qos.c
23e36b3
+++ b/src/up-qos.c
23e36b3
@@ -262,6 +262,7 @@ up_qos_request_latency (UpQos *qos, const gchar *type_text, gint value, gboolean
23e36b3
 	if (type == UP_QOS_KIND_UNKNOWN) {
23e36b3
 		error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "type invalid: %s", type_text);
23e36b3
 		dbus_g_method_return_error (context, error);
23e36b3
+                g_error_free (error);
23e36b3
 		goto out;
23e36b3
 	}
23e36b3
 
23e36b3
@@ -270,6 +271,7 @@ up_qos_request_latency (UpQos *qos, const gchar *type_text, gint value, gboolean
23e36b3
 	if (sender == NULL) {
23e36b3
 		error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "no DBUS sender");
23e36b3
 		dbus_g_method_return_error (context, error);
23e36b3
+                g_error_free (error);
23e36b3
 		goto out;
23e36b3
 	}
23e36b3
 
23e36b3
@@ -291,6 +293,7 @@ up_qos_request_latency (UpQos *qos, const gchar *type_text, gint value, gboolean
23e36b3
 	if (!retval) {
23e36b3
 		error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "cannot get UID");
23e36b3
 		dbus_g_method_return_error (context, error);
23e36b3
+                g_error_free (error);
23e36b3
 		goto out;
23e36b3
 	}
23e36b3
 
23e36b3
@@ -299,6 +302,7 @@ up_qos_request_latency (UpQos *qos, const gchar *type_text, gint value, gboolean
23e36b3
 	if (!retval) {
23e36b3
 		error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "cannot get PID");
23e36b3
 		dbus_g_method_return_error (context, error);
23e36b3
+                g_error_free (error);
23e36b3
 		goto out;
23e36b3
 	}
23e36b3
 
23e36b3
@@ -307,6 +311,7 @@ up_qos_request_latency (UpQos *qos, const gchar *type_text, gint value, gboolean
23e36b3
 	if (cmdline == NULL) {
23e36b3
 		error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "cannot get cmdline");
23e36b3
 		dbus_g_method_return_error (context, error);
23e36b3
+                g_error_free (error);
23e36b3
 		goto out;
23e36b3
 	}
23e36b3
 
23e36b3
@@ -359,6 +364,7 @@ up_qos_cancel_request (UpQos *qos, guint cookie, DBusGMethodInvocation *context)
23e36b3
 		error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL,
23e36b3
 				     "Cannot find request for #%i", cookie);
23e36b3
 		dbus_g_method_return_error (context, error);
23e36b3
+                g_error_free (error);
23e36b3
 		goto out;
23e36b3
 	}
23e36b3
 
23e36b3
@@ -367,6 +373,7 @@ up_qos_cancel_request (UpQos *qos, guint cookie, DBusGMethodInvocation *context)
23e36b3
 	if (sender == NULL) {
23e36b3
 		error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "no DBUS sender");
23e36b3
 		dbus_g_method_return_error (context, error);
23e36b3
+                g_error_free (error);
23e36b3
 		goto out;
23e36b3
 	}
23e36b3
 
23e36b3
@@ -388,6 +395,8 @@ up_qos_cancel_request (UpQos *qos, guint cookie, DBusGMethodInvocation *context)
23e36b3
 	/* TODO: if persistent remove from datadase */
23e36b3
 
23e36b3
 	g_signal_emit (qos, signals [REQUESTS_CHANGED], 0);
23e36b3
+
23e36b3
+	dbus_g_method_return (context, NULL);
23e36b3
 out:
23e36b3
 	if (subject != NULL)
23e36b3
 		g_object_unref (subject);
23e36b3
@@ -430,6 +439,7 @@ up_qos_set_minimum_latency (UpQos *qos, const gchar *type_text, gint value, DBus
23e36b3
 	if (type == UP_QOS_KIND_UNKNOWN) {
23e36b3
 		error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "type invalid: %s", type_text);
23e36b3
 		dbus_g_method_return_error (context, error);
23e36b3
+                g_error_free (error);
23e36b3
 		return;
23e36b3
 	}
23e36b3