From 089483a733f3ed93ea9a92b6ec30d7799df45618 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 5 Apr 2011 15:56:29 +0100 Subject: [PATCH 11/15] dbus-gobject: add and use connection_send_or_die to check for OOM --- dbus/dbus-gobject.c | 39 ++++++++++++++++++++++++--------------- 1 files changed, 24 insertions(+), 15 deletions(-) diff --git a/dbus/dbus-gobject.c b/dbus/dbus-gobject.c index 678a227..305db08 100644 --- a/dbus/dbus-gobject.c +++ b/dbus/dbus-gobject.c @@ -72,6 +72,17 @@ error_or_die (DBusMessage *in_reply_to, return reply; } +static void +connection_send_or_die (DBusConnection *connection, + DBusMessage *message) +{ + g_return_if_fail (connection != NULL); + g_return_if_fail (message != NULL); + + if (!dbus_connection_send (connection, message, NULL)) + g_error ("dbus_connection_send failed: out of memory?"); +} + static char *lookup_property_name (GObject *object, const char *wincaps_propiface, const char *requested_propname); @@ -991,7 +1002,7 @@ handle_introspect (DBusConnection *connection, DBUS_TYPE_STRING, &xml->str, DBUS_TYPE_INVALID); - dbus_connection_send (connection, ret, NULL); + connection_send_or_die (connection, ret); dbus_message_unref (ret); g_string_free (xml, TRUE); @@ -1647,7 +1658,7 @@ invoke_object_method (GObject *object, g_free (in_signature); g_array_free (types_array, TRUE); reply = error_or_die (message, "org.freedesktop.DBus.GLib.ErrorError", error->message); - dbus_connection_send (connection, reply, NULL); + connection_send_or_die (connection, reply); dbus_message_unref (reply); g_error_free (error); return DBUS_HANDLER_RESULT_HANDLED; @@ -1930,9 +1941,7 @@ invoke_object_method (GObject *object, if (reply) { - if (!dbus_connection_send (connection, reply, NULL)) - g_error ("dbus_connection_send failed: out of memory?"); - + connection_send_or_die (connection, reply); dbus_message_unref (reply); } @@ -2030,7 +2039,7 @@ error: ret = error_or_die (message, DBUS_ERROR_ACCESS_DENIED, error_message); g_free (error_message); - dbus_connection_send (connection, ret, NULL); + connection_send_or_die (connection, ret); dbus_message_unref (ret); return FALSE; } @@ -2181,7 +2190,7 @@ object_registration_message (DBusConnection *connection, g_warning ("Property get, set or set all had too many arguments\n"); out: - dbus_connection_send (connection, ret, NULL); + connection_send_or_die (connection, ret); dbus_message_unref (ret); return DBUS_HANDLER_RESULT_HANDLED; } @@ -2263,8 +2272,8 @@ emit_signal_for_registration (ObjectRegistration *o, goto out; } } - dbus_connection_send (DBUS_CONNECTION_FROM_G_CONNECTION (sigclosure->connection), - signal, NULL); + connection_send_or_die (DBUS_CONNECTION_FROM_G_CONNECTION (sigclosure->connection), + signal); out: dbus_message_unref (signal); } @@ -3047,7 +3056,8 @@ dbus_g_method_get_reply (DBusGMethodInvocation *context) void dbus_g_method_send_reply (DBusGMethodInvocation *context, DBusMessage *reply) { - dbus_connection_send (dbus_g_connection_get_connection (context->connection), reply, NULL); + connection_send_or_die (dbus_g_connection_get_connection (context->connection), + reply); dbus_message_unref (reply); dbus_g_connection_unref (context->connection); @@ -3102,7 +3112,8 @@ dbus_g_method_return (DBusGMethodInvocation *context, ...) } va_end (args); - dbus_connection_send (dbus_g_connection_get_connection (context->connection), reply, NULL); + connection_send_or_die (dbus_g_connection_get_connection (context->connection), + reply); dbus_message_unref (reply); g_free (out_sig); @@ -3132,10 +3143,8 @@ dbus_g_method_return_error (DBusGMethodInvocation *context, const GError *error) goto out; reply = gerror_to_dbus_error_message (context->object, dbus_g_message_get_message (context->message), error); - if (!dbus_connection_send ( - dbus_g_connection_get_connection (context->connection), reply, NULL)) - g_error ("dbus_connection_send failed: out of memory?"); - + connection_send_or_die ( + dbus_g_connection_get_connection (context->connection), reply); dbus_message_unref (reply); out: -- 1.7.4.1