From fa41ada6441f818c6a77c27fbc930503008efc10 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Tue, 19 Jul 2022 22:35:35 +0200 Subject: library: Do not initialize callbacks list with placeholder element This does not seem to be needed. Change-Id: I44196b316411673b19099aad528d20f98ad72136 --- libsessiond/src/lib.c | 51 ++++++++++++++------------------------------------- 1 file changed, 14 insertions(+), 37 deletions(-) diff --git a/libsessiond/src/lib.c b/libsessiond/src/lib.c index 6551bec..4e90cf1 100644 --- a/libsessiond/src/lib.c +++ b/libsessiond/src/lib.c @@ -611,18 +611,6 @@ static void client_data_cleansweep_mt( signal_client_data_t *signal_client_data, free(signal_client_data); } -static int init_callbacks_list(client_callbacks_data_t *callbacks_data, GVariant *params) { - - if (callbacks_data->list == NULL) { - signal_client_data_t *signal_client_empty_data = make_new_signal_callback_client_data(NULL, NULL, params); - if (signal_client_empty_data == NULL) { - return_with_log_error_result_(SUBSESSION_ERROR_OUT_OF_MEMORY) - } - callbacks_data->list = g_list_append(callbacks_data->list, (gpointer) signal_client_empty_data); - } - return SUBSESSION_ERROR_NONE; -} - static void async_method_reply_handler(GObject *source_obj, GAsyncResult *res, gpointer userdata) { g_autofree reply_client_data_t * reply_info = (reply_client_data_t *) userdata; @@ -734,25 +722,19 @@ typedef struct { } registered_signal_t; -static registered_signal_t subsession_register_event_in_list(client_callbacks_data_t *callbacks_data, GVariant *init_params, GVariant *params, subsession_event_callback cb, void *cb_data) { +static registered_signal_t subsession_register_event_in_list(client_callbacks_data_t *callbacks_data, GVariant *params, subsession_event_callback cb, void *cb_data) { registered_signal_t registered_signal = {0}; g_mutex_lock(&callbacks_data->mutex); - int init_callbacks_res = init_callbacks_list(callbacks_data, init_params); - - if(init_callbacks_res != SUBSESSION_ERROR_NONE) { - g_mutex_unlock(&callbacks_data->mutex); - registered_signal.error = SUBSESSION_ERROR_OUT_OF_MEMORY; - return registered_signal; - } - - GList *found_data = g_list_find_custom(callbacks_data->list, (gconstpointer)params, g_compare_session_uid); - if (found_data != NULL) { - registered_signal.error = SUBSESSION_ERROR_ALREADY_EXISTS; - g_mutex_unlock(&callbacks_data->mutex); - return registered_signal; + if (callbacks_data->list) { + GList *found_data = g_list_find_custom(callbacks_data->list, (gconstpointer)params, g_compare_session_uid); + if (found_data != NULL) { + registered_signal.error = SUBSESSION_ERROR_ALREADY_EXISTS; + g_mutex_unlock(&callbacks_data->mutex); + return registered_signal; + } } signal_client_data_t *signal_client_data = make_new_signal_callback_client_data(cb, cb_data, params); @@ -769,8 +751,6 @@ static registered_signal_t subsession_register_event_in_list(client_callbacks_da return registered_signal; } -#define default_wait_params_ g_variant_new("(i)", -1), params - #define dbus_data_(callbacks_data_mt, params) \ callbacks_data_mt.dbus_method_call, \ params, \ @@ -791,13 +771,12 @@ static int register_event_callback(client_callbacks_data_t *callbacks_data, GDBu callback_is_null(cb))) ) - GVariant * params = g_variant_new("(i)", session_uid); - - if(params == NULL) { + GVariant *params = g_variant_new("(i)", session_uid); + if (params == NULL) { return_with_log_error_result_(SUBSESSION_ERROR_OUT_OF_MEMORY) } - registered_signal_t registered_signal = subsession_register_event_in_list(callbacks_data, default_wait_params_, cb, cb_data); + registered_signal_t registered_signal = subsession_register_event_in_list(callbacks_data, params, cb, cb_data); if(registered_signal.error != SUBSESSION_ERROR_NONE) { LOGE("registered_signal.error = %d", registered_signal.error); @@ -827,10 +806,8 @@ static int subscribe_only_callback(client_callbacks_data_t *callbacks_data, GDBu return_with_log_error_result_(SUBSESSION_ERROR_OUT_OF_MEMORY); } - registered_signal_t registered_signal = subsession_register_event_in_list(callbacks_data, default_wait_params_, cb, cb_data); - - - if(registered_signal.error != SUBSESSION_ERROR_NONE) { + registered_signal_t registered_signal = subsession_register_event_in_list(callbacks_data, params, cb, cb_data); + if (registered_signal.error != SUBSESSION_ERROR_NONE) { return registered_signal.error; } @@ -885,7 +862,7 @@ static int unregister_event_callback(client_callbacks_data_t *callbacks_data, in free(signal_data); g_mutex_lock(&callbacks_data->mutex); - if(g_list_length(callbacks_data->list) <= 1) { + if (callbacks_data->list == NULL) { g_dbus_connection_signal_unsubscribe(session_connection_data.connection, callbacks_data->dbus_signal_subscribed); callbacks_data->dbus_signal_subscribed = 0; } -- cgit v1.2.3