aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/alsa/alsa-transaction.c
diff options
context:
space:
mode:
authorThierry Bultel <thierry.bultel@iot.bzh>2019-02-13 11:30:53 +0100
committerThierry Bultel <thierry.bultel@iot.bzh>2019-02-18 15:51:30 +0100
commitedeccfc0d062117bdb74c86044e197372ca25885 (patch)
tree188927e042902e0907d128aed5902a4b84ec0b39 /plugins/alsa/alsa-transaction.c
parent0e9718e4158355093b281c1376ba9b0ed049d447 (diff)
alsa-transaction: simplify the cleanup
This simplifies the invocation of cleanup, by only using AlsaMixerTransactionDelete that performs the 3 actions of cleanup, removal from list, and memory freeing. Fixes a bug at MixerExit, because the first transaction was not removed from the list and led to a double free error. Also added a boolean parameter to AlsaMixerTransactionObjectDelete (was AlsaMixerTransactionObjectForget before), that decides wether or not the found object must be destroyed with its destructor (for most of the cases) or simply freed in memory (which is needed for loop device). Change-Id: I2eacbf80a22e3d556dc432d393a1807fcd7c47fb Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
Diffstat (limited to 'plugins/alsa/alsa-transaction.c')
-rw-r--r--plugins/alsa/alsa-transaction.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/plugins/alsa/alsa-transaction.c b/plugins/alsa/alsa-transaction.c
index 1677582..c35ea81 100644
--- a/plugins/alsa/alsa-transaction.c
+++ b/plugins/alsa/alsa-transaction.c
@@ -6,16 +6,19 @@
#include "wrap-json.h"
-void AlsaMixerTransactionDelete(AlsaMixerTransaction * transaction) {
+static void AlsaMixerTransactionFree(AlsaMixerTransaction * transaction) {
free((char*)transaction->uid);
free(transaction);
}
AlsaMixerTransaction * AlsaMixerTransactionNew(struct SoftMixerT_ * mixer, const char * uid) {
+
AlsaMixerTransaction * transaction = (AlsaMixerTransaction *) malloc(sizeof(AlsaMixerTransaction));
if (transaction == NULL)
goto fail;
+ AFB_API_INFO(mixer->api, "-------- NEW TRANSACTION %s --------", uid);
+
CDS_INIT_LIST_HEAD(&transaction->item_list);
transaction->uid = strdup(uid);
if (transaction->uid == NULL) {
@@ -33,14 +36,15 @@ fail:
return NULL;
}
-void AlsaMixerTransactionDataListDestroy(AlsaMixerTransaction* list) {
- free(list);
-}
-void AlsaMixerTransactionObjectForget(AlsaMixerTransaction* list, void * object) {
+void AlsaMixerTransactionObjectDelete(AlsaMixerTransaction* transaction, void * object, bool destructor) {
AlsaMixerTransactionDataItem *item, *tmp;
- cds_list_for_each_entry_safe(item, tmp, &list->item_list, list_entry)
+ cds_list_for_each_entry_safe(item, tmp, &transaction->item_list, list_entry)
if (item->object == object) {
+
+ if (destructor && item->destructor)
+ item->destructor(transaction->mixer, item->object);
+
cds_list_del(&item->list_entry);
free(item);
}
@@ -67,7 +71,7 @@ fail:
}
-void AlsaMixerTransactionDoCleanup(AlsaMixerTransaction* transaction) {
+static void AlsaMixerTransactionDoCleanup(AlsaMixerTransaction* transaction) {
AlsaMixerTransactionDataItem * item, *sav;
AFB_API_INFO(transaction->mixer->api, "%s for transaction %s", __func__, transaction->uid);
@@ -106,11 +110,6 @@ void AlsaMixerTransactionVerbCB(afb_req_t request) {
}
if (strcmp(action, "remove") == 0) {
- AlsaMixerTransactionDoCleanup(transaction);
-
- // remove this transaction for the list of mixer
- cds_list_del(&transaction->transaction_node);
-
error = afb_api_del_verb(transaction->mixer->api, transaction->uid, (void**)NULL);
if (error) {
afb_req_fail(request, "verb deletion" , "verb was not removed");
@@ -133,3 +132,10 @@ fail:
return;
}
+
+void AlsaMixerTransactionDelete(AlsaMixerTransaction * transaction) {
+ AlsaMixerTransactionDoCleanup(transaction);
+ // remove this transaction for the list of mixer
+ cds_list_del(&transaction->transaction_node);
+ AlsaMixerTransactionFree(transaction);
+}