spa: bluez: add cancel_and_unref() dbus helper

This function cancels and unrefs a DBusPendingCall and
resets the pointer to NULL.
This commit is contained in:
Barnabás Pőcze 2023-07-11 17:01:00 +02:00
parent 1025d5c600
commit 183270f53c
4 changed files with 39 additions and 53 deletions

View file

@ -7,6 +7,7 @@
#include <ModemManager.h>
#include "dbus-helpers.h"
#include "modemmanager.h"
#define DBUS_INTERFACE_OBJECTMANAGER "org.freedesktop.DBus.ObjectManager"
@ -56,8 +57,7 @@ static bool mm_dbus_connection_send_with_reply(struct impl *this, DBusMessage *m
ret = dbus_pending_call_set_notify(pending_call, function, user_data, NULL);
if (!ret) {
spa_log_debug(this->log, "dbus set notify failure");
dbus_pending_call_cancel(pending_call);
dbus_pending_call_unref(pending_call);
cancel_and_unref(&pending_call);
goto out;
}
@ -455,13 +455,11 @@ finish:
dbus_message_unref(r);
}
static void call_free(struct call *call) {
static void call_free(struct call *call)
{
spa_list_remove(&call->link);
if (call->pending != NULL) {
dbus_pending_call_cancel(call->pending);
dbus_pending_call_unref(call->pending);
}
cancel_and_unref(&call->pending);
if (call->number)
free(call->number);
@ -477,10 +475,7 @@ static void mm_clean_voice(struct impl *this)
spa_list_consume(call, &this->call_list, link)
call_free(call);
if (this->voice_pending != NULL) {
dbus_pending_call_cancel(this->voice_pending);
dbus_pending_call_unref(this->voice_pending);
}
cancel_and_unref(&this->voice_pending);
if (this->ops->set_call_setup)
this->ops->set_call_setup(CIND_CALLSETUP_NONE, this->user_data);
@ -1158,10 +1153,7 @@ void mm_unregister(void *data)
{
struct impl *this = data;
if (this->pending != NULL) {
dbus_pending_call_cancel(this->pending);
dbus_pending_call_unref(this->pending);
}
cancel_and_unref(&this->pending);
mm_clean_voice(this);
mm_clean_modem3gpp(this);