From 57df88bb0b4ce656855410a8c2969d93475c2f11 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 24 Feb 2009 16:36:16 -0500 Subject: Proper fix for memory handling problem. sbus_message_handler is not responsible anymore for sending back data in any case. Transfer this responsibility to the handler function called. This way both synchronous and asynchronous funstions use the interface the same way and can properly free memory referenced by the reply after the send buffer has been filled in and all copies are done in sbus_conn_send_reply() --- server/polkit/sssd_polkit.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'server/polkit') diff --git a/server/polkit/sssd_polkit.c b/server/polkit/sssd_polkit.c index 6c7d0e1e8..03436472d 100644 --- a/server/polkit/sssd_polkit.c +++ b/server/polkit/sssd_polkit.c @@ -35,7 +35,7 @@ struct spk_ctx { struct sbus_srv_ctx *sbus_srv; }; -static int service_identity(DBusMessage *message, void *data, DBusMessage **r) +static int service_identity(DBusMessage *message, struct sbus_conn_ctx *sconn) { dbus_uint16_t version = POLKIT_VERSION; const char *name = POLKIT_SERVICE_NAME; @@ -45,41 +45,54 @@ static int service_identity(DBusMessage *message, void *data, DBusMessage **r) DEBUG(4, ("Sending identity data [%s,%d]\n", name, version)); reply = dbus_message_new_method_return(message); + if (!reply) return ENOMEM; + ret = dbus_message_append_args(reply, DBUS_TYPE_STRING, &name, DBUS_TYPE_UINT16, &version, DBUS_TYPE_INVALID); if (!ret) { + dbus_message_unref(reply); return EIO; } - *r = reply; + /* send reply back */ + sbus_conn_send_reply(sconn, reply); + dbus_message_unref(reply); + return EOK; } -static int service_pong(DBusMessage *message, void *data, DBusMessage **r) +static int service_pong(DBusMessage *message, struct sbus_conn_ctx *sconn) { DBusMessage *reply; dbus_bool_t ret; reply = dbus_message_new_method_return(message); + if (!reply) return ENOMEM; + ret = dbus_message_append_args(reply, DBUS_TYPE_INVALID); if (!ret) { + dbus_message_unref(reply); return EIO; } - *r = reply; + /* send reply back */ + sbus_conn_send_reply(sconn, reply); + dbus_message_unref(reply); + return EOK; } -static int service_reload(DBusMessage *message, void *data, DBusMessage **r) { +static int service_reload(DBusMessage *message, struct sbus_conn_ctx *sconn) +{ /* Monitor calls this function when we need to reload * our configuration information. Perform whatever steps * are needed to update the configuration objects. */ /* Send an empty reply to acknowledge receipt */ - return service_pong(message, data, r); + return service_pong(message, sconn); } struct sbus_method mon_sbus_methods[] = { -- cgit