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/sbus/sssd_dbus.h | 11 ++++------- server/sbus/sssd_dbus_connection.c | 23 ++++++++++++++--------- server/sbus/sssd_dbus_server.c | 1 + 3 files changed, 19 insertions(+), 16 deletions(-) (limited to 'server/sbus') diff --git a/server/sbus/sssd_dbus.h b/server/sbus/sssd_dbus.h index 5fec9c80..a05d229a 100644 --- a/server/sbus/sssd_dbus.h +++ b/server/sbus/sssd_dbus.h @@ -27,7 +27,7 @@ struct sbus_srv_ctx; #include "dbus/dbus.h" -typedef int (*sbus_msg_handler_fn)(DBusMessage *, void *, DBusMessage **); +typedef int (*sbus_msg_handler_fn)(DBusMessage *, struct sbus_conn_ctx *); /* * sbus_conn_destructor_fn @@ -66,12 +66,6 @@ struct sbus_method_ctx { sbus_msg_handler_fn introspect_fn; }; -struct sbus_message_handler_ctx { - struct sbus_conn_ctx *conn_ctx; - struct sbus_method_ctx *method_ctx; - char *introspection_xml; -}; - /* Server Functions */ int sbus_new_server(TALLOC_CTX *mem_ctx, struct event_context *ev, struct sbus_method_ctx *ctx, @@ -129,4 +123,7 @@ DBusHandlerResult sbus_message_handler(DBusConnection *conn, DBusMessage *message, void *user_data); +void sbus_conn_send_reply(struct sbus_conn_ctx *conn_ctx, + DBusMessage *reply); + #endif /* _SSSD_DBUS_H_*/ diff --git a/server/sbus/sssd_dbus_connection.c b/server/sbus/sssd_dbus_connection.c index d02dc6c8..9b3da9cc 100644 --- a/server/sbus/sssd_dbus_connection.c +++ b/server/sbus/sssd_dbus_connection.c @@ -18,6 +18,11 @@ struct sbus_conn_ctx { void *pvt_data; /* Private data for this connection */ }; +struct sbus_message_handler_ctx { + struct sbus_conn_ctx *conn_ctx; + struct sbus_method_ctx *method_ctx; +}; + struct sbus_conn_watch_ctx { DBusWatch *watch; int fd; @@ -354,6 +359,7 @@ int sbus_new_connection(TALLOC_CTX *ctx, struct event_context *ev, if (!dbus_conn) { DEBUG(1, ("Failed to open connection: name=%s, message=%s\n", dbus_error.name, dbus_error.message)); + if (dbus_error_is_set(&dbus_error)) dbus_error_free(&dbus_error); return EIO; } @@ -509,7 +515,7 @@ DBusHandlerResult sbus_message_handler(DBusConnection *conn, for (i = 0; ctx->method_ctx->methods[i].method != NULL; i++) { if (strcmp(method, ctx->method_ctx->methods[i].method) == 0) { found = 1; - ret = ctx->method_ctx->methods[i].fn(message, ctx, &reply); + ret = ctx->method_ctx->methods[i].fn(message, ctx->conn_ctx); if (ret != EOK) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; break; } @@ -532,7 +538,7 @@ DBusHandlerResult sbus_message_handler(DBusConnection *conn, /* If we have been asked for introspection data and we have * an introspection function registered, user that. */ - ret = ctx->method_ctx->introspect_fn(message, ctx, &reply); + ret = ctx->method_ctx->introspect_fn(message, ctx->conn_ctx); if (ret != EOK) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } } @@ -540,13 +546,6 @@ DBusHandlerResult sbus_message_handler(DBusConnection *conn, return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } - DEBUG(5, ("Method %s complete. Reply was %ssent.\n", method, reply?"":"not ")); - - if (reply) { - dbus_connection_send(conn, reply, NULL); - dbus_message_unref(reply); - } - return DBUS_HANDLER_RESULT_HANDLED; } @@ -654,3 +653,9 @@ bool sbus_conn_disconnecting(struct sbus_conn_ctx *conn_ctx) if (conn_ctx->disconnect == 1) return true; return false; } + +void sbus_conn_send_reply(struct sbus_conn_ctx *conn_ctx, DBusMessage *reply) +{ + dbus_connection_send(conn_ctx->conn, reply, NULL); +} + diff --git a/server/sbus/sssd_dbus_server.c b/server/sbus/sssd_dbus_server.c index 03cd6524..eae1ce67 100644 --- a/server/sbus/sssd_dbus_server.c +++ b/server/sbus/sssd_dbus_server.c @@ -272,6 +272,7 @@ int sbus_new_server(TALLOC_CTX *mem_ctx, if (!dbus_server) { DEBUG(1,("dbus_server_listen failed! (name=%s, message=%s)\n", dbus_error.name, dbus_error.message)); + if (dbus_error_is_set(&dbus_error)) dbus_error_free(&dbus_error); return EIO; } -- cgit