diff --git a/spa/plugins/bluez5/backend-hsphfpd.c b/spa/plugins/bluez5/backend-hsphfpd.c index 1ef50449e..2fb42b229 100644 --- a/spa/plugins/bluez5/backend-hsphfpd.c +++ b/spa/plugins/bluez5/backend-hsphfpd.c @@ -18,6 +18,7 @@ #include #include "defs.h" +#include "dbus-helpers.h" static struct spa_log_topic log_topic = SPA_LOG_TOPIC(0, "spa.bluez5.hsphfpd"); #undef SPA_LOG_TOPIC_DEFAULT @@ -846,7 +847,7 @@ static void hsphfpd_audio_acquire_reply(DBusPendingCall *pending, void *user_dat backend->acquire_in_progress = false; - r = dbus_pending_call_steal_reply(pending); + r = steal_reply_and_unref(&pending); if (r == NULL) return; @@ -889,7 +890,6 @@ static void hsphfpd_audio_acquire_reply(DBusPendingCall *pending, void *user_dat finish: dbus_message_unref(r); - dbus_pending_call_unref(pending); if (ret < 0) spa_bt_transport_set_state(transport, SPA_BT_TRANSPORT_STATE_ERROR); @@ -1179,7 +1179,7 @@ static void hsphfpd_get_endpoints_reply(DBusPendingCall *pending, void *user_dat DBusMessage *r; DBusMessageIter i, array_i; - r = dbus_pending_call_steal_reply(pending); + r = steal_reply_and_unref(&pending); if (r == NULL) return; @@ -1212,7 +1212,6 @@ static void hsphfpd_get_endpoints_reply(DBusPendingCall *pending, void *user_dat finish: dbus_message_unref(r); - dbus_pending_call_unref(pending); } static int backend_hsphfpd_register(void *data) diff --git a/spa/plugins/bluez5/backend-native.c b/spa/plugins/bluez5/backend-native.c index 2476f7dfc..74757c78e 100644 --- a/spa/plugins/bluez5/backend-native.c +++ b/spa/plugins/bluez5/backend-native.c @@ -33,6 +33,7 @@ #include #endif +#include "dbus-helpers.h" #include "modemmanager.h" #include "upower.h" @@ -2413,7 +2414,7 @@ static void register_profile_reply(DBusPendingCall *pending, void *user_data) struct impl *backend = user_data; DBusMessage *r; - r = dbus_pending_call_steal_reply(pending); + r = steal_reply_and_unref(&pending); if (r == NULL) return; @@ -2431,9 +2432,8 @@ static void register_profile_reply(DBusPendingCall *pending, void *user_data) goto finish; } - finish: +finish: dbus_message_unref(r); - dbus_pending_call_unref(pending); } static int register_profile(struct impl *backend, const char *profile, const char *uuid) diff --git a/spa/plugins/bluez5/backend-ofono.c b/spa/plugins/bluez5/backend-ofono.c index c24887517..103ed685e 100644 --- a/spa/plugins/bluez5/backend-ofono.c +++ b/spa/plugins/bluez5/backend-ofono.c @@ -22,6 +22,7 @@ #include #include "defs.h" +#include "dbus-helpers.h" #define INITIAL_INTERVAL_NSEC (500 * SPA_NSEC_PER_MSEC) #define ACTION_INTERVAL_NSEC (3000 * SPA_NSEC_PER_MSEC) @@ -633,7 +634,7 @@ static void ofono_getcards_reply(DBusPendingCall *pending, void *user_data) DBusMessage *r; DBusMessageIter i, array_i, struct_i, props_i; - r = dbus_pending_call_steal_reply(pending); + r = steal_reply_and_unref(&pending); if (r == NULL) return; @@ -665,7 +666,6 @@ static void ofono_getcards_reply(DBusPendingCall *pending, void *user_data) finish: dbus_message_unref(r); - dbus_pending_call_unref(pending); } static int backend_ofono_register(void *data) diff --git a/spa/plugins/bluez5/bluez5-dbus.c b/spa/plugins/bluez5/bluez5-dbus.c index a79c1b18b..e22c0d415 100644 --- a/spa/plugins/bluez5/bluez5-dbus.c +++ b/spa/plugins/bluez5/bluez5-dbus.c @@ -351,10 +351,8 @@ static void on_battery_provider_registered(DBusPendingCall *pending_call, DBusMessage *reply; struct spa_bt_device *device = data; - reply = dbus_pending_call_steal_reply(pending_call); - dbus_pending_call_unref(pending_call); - - device->battery_pending_call = NULL; + spa_assert(device->battery_pending_call == pending_call); + reply = steal_reply_and_unref(&device->battery_pending_call); if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) { spa_log_error(device->monitor->log, "Failed to register battery provider. Error: %s", dbus_message_get_error_name(reply)); @@ -3228,11 +3226,8 @@ static void transport_set_property_volume_reply(DBusPendingCall *pending, void * DBusError err = DBUS_ERROR_INIT; DBusMessage *r; - r = dbus_pending_call_steal_reply(pending); - spa_assert(transport->volume_call == pending); - dbus_pending_call_unref(pending); - transport->volume_call = NULL; + r = steal_reply_and_unref(&transport->volume_call); if (dbus_set_error_from_message(&err, r)) { spa_log_info(monitor->log, "transport %p: set volume failed for transport %s: %s", @@ -3382,11 +3377,8 @@ static void transport_acquire_reply(DBusPendingCall *pending, void *user_data) DBusMessage *r; struct spa_bt_transport *t, *t_linked; - r = dbus_pending_call_steal_reply(pending); - spa_assert(transport->acquire_call == pending); - dbus_pending_call_unref(pending); - transport->acquire_call = NULL; + r = steal_reply_and_unref(&transport->acquire_call); spa_bt_device_update_last_bluez_action_time(device); @@ -3967,11 +3959,8 @@ static void media_codec_switch_reply(DBusPendingCall *pending, void *user_data) struct spa_bt_device *device = sw->device; DBusMessage *r; - r = dbus_pending_call_steal_reply(pending); - spa_assert(sw->pending == pending); - dbus_pending_call_unref(pending); - sw->pending = NULL; + r = steal_reply_and_unref(&sw->pending); spa_bt_device_update_last_bluez_action_time(device); @@ -4450,9 +4439,7 @@ static void bluez_register_endpoint_legacy_reply(DBusPendingCall *pending, void struct spa_bt_monitor *monitor = adapter->monitor; DBusMessage *r; - r = dbus_pending_call_steal_reply(pending); - dbus_pending_call_unref(pending); - + r = steal_reply_and_unref(&pending); if (r == NULL) return; @@ -4751,9 +4738,7 @@ static void bluez_register_application_a2dp_reply(DBusPendingCall *pending, void DBusMessage *r; bool fallback = true; - r = dbus_pending_call_steal_reply(pending); - dbus_pending_call_unref(pending); - + r = steal_reply_and_unref(&pending); if (r == NULL) return; @@ -4784,9 +4769,7 @@ static void bluez_register_application_bap_reply(DBusPendingCall *pending, void struct spa_bt_monitor *monitor = adapter->monitor; DBusMessage *r; - r = dbus_pending_call_steal_reply(pending); - dbus_pending_call_unref(pending); - + r = steal_reply_and_unref(&pending); if (r == NULL) return; @@ -5200,12 +5183,8 @@ static void get_managed_objects_reply(DBusPendingCall *pending, void *user_data) DBusMessage *r; DBusMessageIter it[6]; - spa_assert(pending == monitor->get_managed_objects_call); - monitor->get_managed_objects_call = NULL; - - r = dbus_pending_call_steal_reply(pending); - dbus_pending_call_unref(pending); - + spa_assert(monitor->get_managed_objects_call == pending); + r = steal_reply_and_unref(&monitor->get_managed_objects_call); if (r == NULL) return; diff --git a/spa/plugins/bluez5/dbus-helpers.h b/spa/plugins/bluez5/dbus-helpers.h index 43b9afd2a..a083a1e04 100644 --- a/spa/plugins/bluez5/dbus-helpers.h +++ b/spa/plugins/bluez5/dbus-helpers.h @@ -19,4 +19,14 @@ static inline void cancel_and_unref(DBusPendingCall **pp) } } +static inline DBusMessage *steal_reply_and_unref(DBusPendingCall **pp) +{ + DBusPendingCall *pending_call = spa_steal_ptr(*pp); + + DBusMessage *reply = dbus_pending_call_steal_reply(pending_call); + dbus_pending_call_unref(pending_call); + + return reply; +} + #endif /* SPA_BLUEZ5_DBUS_HELPERS_H */ diff --git a/spa/plugins/bluez5/modemmanager.c b/spa/plugins/bluez5/modemmanager.c index 99d9eb67c..0f68e1fa5 100644 --- a/spa/plugins/bluez5/modemmanager.c +++ b/spa/plugins/bluez5/modemmanager.c @@ -125,10 +125,7 @@ static void mm_get_call_properties_reply(DBusPendingCall *pending, void *user_da MMCallState state; spa_assert(call->pending == pending); - call->pending = NULL; - - r = dbus_pending_call_steal_reply(pending); - dbus_pending_call_unref(pending); + r = steal_reply_and_unref(&call->pending); if (r == NULL) return; @@ -424,10 +421,7 @@ static void mm_get_managed_objects_reply(DBusPendingCall *pending, void *user_da DBusMessageIter i, array_i; spa_assert(this->pending == pending); - this->pending = NULL; - - r = dbus_pending_call_steal_reply(pending); - dbus_pending_call_unref(pending); + r = steal_reply_and_unref(&this->pending); if (r == NULL) return; @@ -782,10 +776,7 @@ static void mm_get_call_simple_reply(DBusPendingCall *pending, void *data) free(data); spa_assert(call->pending == pending); - call->pending = NULL; - - r = dbus_pending_call_steal_reply(pending); - dbus_pending_call_unref(pending); + r = steal_reply_and_unref(&call->pending); if (r == NULL) return; @@ -815,10 +806,7 @@ static void mm_get_call_create_reply(DBusPendingCall *pending, void *data) free(data); spa_assert(this->voice_pending == pending); - this->voice_pending = NULL; - - r = dbus_pending_call_steal_reply(pending); - dbus_pending_call_unref(pending); + r = steal_reply_and_unref(&this->voice_pending); if (r == NULL) return; diff --git a/spa/plugins/bluez5/upower.c b/spa/plugins/bluez5/upower.c index aca111dd5..5633d9983 100644 --- a/spa/plugins/bluez5/upower.c +++ b/spa/plugins/bluez5/upower.c @@ -44,8 +44,7 @@ static void upower_get_percentage_properties_reply(DBusPendingCall *pending, voi DBusMessage *r; DBusMessageIter i, variant_i; - r = dbus_pending_call_steal_reply(pending); - dbus_pending_call_unref(pending); + r = steal_reply_and_unref(&pending); if (r == NULL) return;