summaryrefslogtreecommitdiffstats
path: root/plugins/alsa/alsa-core-ctl.c
diff options
context:
space:
mode:
authorStephane Desneux <stephane.desneux@iot.bzh>2018-12-22 11:51:54 +0100
committerStephane Desneux <stephane.desneux@iot.bzh>2018-12-22 11:51:54 +0100
commitc85fd2f131c73e8c21e05e1ea80b55d6a787dda6 (patch)
tree248aca4a75556e3546a3c89cac43bcffe3ccf634 /plugins/alsa/alsa-core-ctl.c
parente0f57e523112e1bc73a04e8615d7a21355f0ce0e (diff)
Implemented the bug cleanup at application exit
Fixes most memory leaks in softmixer. The concept of 'transaction' for dynamic streams has been generalized to the objects created at startup. The cleanup is done via a handle set through a atexit() call. Also added a missing strdup in alsa-api-loop, that fixes a double free. Warning, the bluez-alsa PCM are not closed in this version. This is intentional due to a BUG in the bluealsa ioplug PCM, that crashes upon close (pthread_cancel is used to terminate the io_thread and things get very bad. I have a pending fix for that, relying on a cancellation pipe, but deeper testing must be done). As an effect, only one phone call can be made, else 4a needs to be restarted Change-Id: Idb84cafe15f17c0ef02fcc70296d541dc55a2dcf Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh> Signed-off-by: Stephane Desneux <stephane.desneux@iot.bzh>
Diffstat (limited to 'plugins/alsa/alsa-core-ctl.c')
-rw-r--r--plugins/alsa/alsa-core-ctl.c99
1 files changed, 60 insertions, 39 deletions
diff --git a/plugins/alsa/alsa-core-ctl.c b/plugins/alsa/alsa-core-ctl.c
index dcfd860..020c13c 100644
--- a/plugins/alsa/alsa-core-ctl.c
+++ b/plugins/alsa/alsa-core-ctl.c
@@ -42,7 +42,7 @@ PUBLIC snd_ctl_elem_id_t *AlsaCtlGetNumidElemId(SoftMixerT *mixer, AlsaSndCtlT *
int error;
int index;
snd_ctl_elem_list_t *ctlList = NULL;
- snd_ctl_elem_id_t *elemId;
+ snd_ctl_elem_id_t *elemId = NULL;
snd_ctl_elem_list_alloca(&ctlList);
@@ -50,14 +50,14 @@ PUBLIC snd_ctl_elem_id_t *AlsaCtlGetNumidElemId(SoftMixerT *mixer, AlsaSndCtlT *
AFB_ApiError(mixer->api,
"%s [%s] fail retrieve controls",
__func__, ALSA_CTL_UID(sndcard->ctl, string));
- goto OnErrorExit;
+ goto fail;
}
if ((error = snd_ctl_elem_list_alloc_space(ctlList, snd_ctl_elem_list_get_count(ctlList))) < 0) {
AFB_ApiError(mixer->api,
"%s [%s] fail retrieve count",
__func__, ALSA_CTL_UID(sndcard->ctl, string));
- goto OnErrorExit;
+ goto fail;
}
// Fulup: do not understand why snd_ctl_elem_list should be call twice to get a valid ctlCount
@@ -65,7 +65,7 @@ PUBLIC snd_ctl_elem_id_t *AlsaCtlGetNumidElemId(SoftMixerT *mixer, AlsaSndCtlT *
AFB_ApiError(mixer->api,
"%s [%s] fail retrieve controls",
__func__, ALSA_CTL_UID(sndcard->ctl, string));
- goto OnErrorExit;
+ goto fail_space;
}
// loop on control to find the right one
@@ -83,23 +83,25 @@ PUBLIC snd_ctl_elem_id_t *AlsaCtlGetNumidElemId(SoftMixerT *mixer, AlsaSndCtlT *
AFB_ApiNotice(mixer->api,
"%s [%s] fail get numid=%i count",
__func__, ALSA_CTL_UID(sndcard->ctl, string), numid);
- goto OnErrorExit;
+ goto fail_space;
}
- // clear ctl list and return elemid
- snd_ctl_elem_list_clear(ctlList);
- return elemId;
+ snd_ctl_elem_list_free_space(ctlList);
+ return elemId;
-OnErrorExit:
- if (ctlList) snd_ctl_elem_list_clear(ctlList);
+fail_space:
+ snd_ctl_elem_list_free_space(ctlList);
+fail:
return NULL;
+
+
}
PUBLIC snd_ctl_elem_id_t *AlsaCtlGetNameElemId(SoftMixerT *mixer, AlsaSndCtlT *sndcard, const char *ctlName) {
int error;
int index;
snd_ctl_elem_list_t *ctlList = NULL;
- snd_ctl_elem_id_t *elemId;
+ snd_ctl_elem_id_t *elemId = NULL;
snd_ctl_elem_list_alloca(&ctlList);
@@ -107,14 +109,14 @@ PUBLIC snd_ctl_elem_id_t *AlsaCtlGetNameElemId(SoftMixerT *mixer, AlsaSndCtlT *s
AFB_ApiError(mixer->api,
"%s cardid='%s' cardname='%s' fail retrieve controls",
__func__, sndcard->cid.cardid, sndcard->cid.name);
- goto OnErrorExit;
+ goto fail;
}
if ((error = snd_ctl_elem_list_alloc_space(ctlList, snd_ctl_elem_list_get_count(ctlList))) < 0) {
AFB_ApiError(mixer->api,
"%s cardid='%s' cardname='%s' fail retrieve count",
__func__, sndcard->cid.cardid, sndcard->cid.name);
- goto OnErrorExit;
+ goto fail;
}
// Fulup: do not understand why snd_ctl_elem_list should be call twice to get a valid ctlCount
@@ -122,7 +124,7 @@ PUBLIC snd_ctl_elem_id_t *AlsaCtlGetNameElemId(SoftMixerT *mixer, AlsaSndCtlT *s
AFB_ApiError(mixer->api,
"%s cardid='%s' cardname='%s' fail retrieve controls",
__func__, sndcard->cid.cardid, sndcard->cid.name);
- goto OnErrorExit;
+ goto fail_space;
}
// loop on control to find the right one
@@ -138,16 +140,17 @@ PUBLIC snd_ctl_elem_id_t *AlsaCtlGetNameElemId(SoftMixerT *mixer, AlsaSndCtlT *s
if (index == ctlCount) {
AFB_ApiNotice(mixer->api, "AlsaCtlGetNameElemId cardid='%s' cardname='%s' ctl not found name=%s", sndcard->cid.cardid, sndcard->cid.name, ctlName);
- goto OnErrorExit;
+ goto fail_space;
}
- // clear ctl list and return elemid
- snd_ctl_elem_list_clear(ctlList);
- return elemId;
+ snd_ctl_elem_list_free_space(ctlList);
+ return elemId;
+
+fail_space:
+ snd_ctl_elem_list_free_space(ctlList);
+fail:
+ return NULL;
-OnErrorExit:
- if (ctlList) snd_ctl_elem_list_clear(ctlList);
- return NULL;
}
@@ -317,7 +320,7 @@ PUBLIC int AlsaCtlNumidSetLong(SoftMixerT *mixer, AlsaSndCtlT *sndcard, int numi
AFB_ApiError(mixer->api,
"%s cardid=%s cardname=%s fail to find numid=%d",
__func__, sndcard->cid.cardid, sndcard->cid.longname, numid);
- goto OnErrorExit;
+ goto fail;
}
int error = CtlElemIdSetLong(mixer, sndcard, elemId, value);
@@ -325,11 +328,15 @@ PUBLIC int AlsaCtlNumidSetLong(SoftMixerT *mixer, AlsaSndCtlT *sndcard, int numi
AFB_ApiError(mixer->api,
"%s cardid=%s cardname=%s fail to set numid=%d value=%ld",
__func__, sndcard->cid.cardid, sndcard->cid.longname, numid, value);
- goto OnErrorExit;
+ goto fail_elemId;
}
+ free(elemId);
return 0;
-OnErrorExit:
+
+fail_elemId:
+ free(elemId);
+fail:
return -1;
}
@@ -340,7 +347,7 @@ PUBLIC int AlsaCtlNumidGetLong(SoftMixerT *mixer, AlsaSndCtlT *sndcard, int numi
AFB_ApiError(mixer->api,
"%s cardid=%s cardname=%s fail to find numid=%d",
__func__, sndcard->cid.cardid, sndcard->cid.longname, numid);
- goto OnErrorExit;
+ goto fail;
}
int error = CtlElemIdGetLong(mixer, sndcard, elemId, value);
@@ -348,12 +355,16 @@ PUBLIC int AlsaCtlNumidGetLong(SoftMixerT *mixer, AlsaSndCtlT *sndcard, int numi
AFB_ApiError(mixer->api,
"%s cardid=%s cardname=%s fail to get numid=%d value",
__func__, sndcard->cid.cardid, sndcard->cid.longname, numid);
- goto OnErrorExit;
+ goto fail_elemId;
}
+ free(elemId);
return 0;
-OnErrorExit:
- return -1;
+
+fail_elemId:
+ free(elemId);
+fail:
+ return -1;
}
PUBLIC int AlsaCtlNameSetLong(SoftMixerT *mixer, AlsaSndCtlT *sndcard, const char *ctlName, long value) {
@@ -363,7 +374,7 @@ PUBLIC int AlsaCtlNameSetLong(SoftMixerT *mixer, AlsaSndCtlT *sndcard, const cha
AFB_ApiError(mixer->api,
"%s cardid=%s cardname=%s fail to find crlName=%s",
__func__, sndcard->cid.cardid, sndcard->cid.longname, ctlName);
- goto OnErrorExit;
+ goto fail;
}
int error = CtlElemIdSetLong(mixer, sndcard, elemId, value);
@@ -371,11 +382,15 @@ PUBLIC int AlsaCtlNameSetLong(SoftMixerT *mixer, AlsaSndCtlT *sndcard, const cha
AFB_ApiError(mixer->api,
"%s cardid=%s cardname=%s fail to set crlName=%s value=%ld",
__func__, sndcard->cid.cardid, sndcard->cid.longname, ctlName, value);
- goto OnErrorExit;
+ goto fail_elemId;
}
+ free(elemId);
return 0;
-OnErrorExit:
+
+fail_elemId:
+ free(elemId);
+fail:
return -1;
}
@@ -386,7 +401,7 @@ PUBLIC int AlsaCtlNameGetLong(SoftMixerT *mixer, AlsaSndCtlT *sndcard, const cha
AFB_ApiError(mixer->api,
"%s cardid=%s cardname=%s fail to find crlName=%s",
__func__, sndcard->cid.cardid, sndcard->cid.longname, ctlName);
- goto OnErrorExit;
+ goto fail;
}
int error = CtlElemIdGetLong(mixer, sndcard, elemId, value);
@@ -394,11 +409,15 @@ PUBLIC int AlsaCtlNameGetLong(SoftMixerT *mixer, AlsaSndCtlT *sndcard, const cha
AFB_ApiError(mixer->api,
"%s cardid=%s cardname=%s fail to get crlName=%s value",
__func__, sndcard->cid.cardid, sndcard->cid.longname, ctlName);
- goto OnErrorExit;
+ goto fail_elemId;
}
+ free(elemId);
return 0;
-OnErrorExit:
+
+fail_elemId:
+ free(elemId);
+fail:
return -1;
}
@@ -462,7 +481,7 @@ PUBLIC int AlsaCtlCreateControl(SoftMixerT *mixer, AlsaSndCtlT *sndcard, char* c
AFB_ApiError(mixer->api,
"%s cardid=%s cardname=%s fail to create ctlName=%s",
__func__, sndcard->cid.cardid, sndcard->cid.longname, ctlName);
- goto OnErrorExit;
+ goto fail;
}
elemId = AlsaCtlGetNumidElemId(mixer, sndcard, numid);
@@ -473,15 +492,17 @@ PUBLIC int AlsaCtlCreateControl(SoftMixerT *mixer, AlsaSndCtlT *sndcard, char* c
AFB_ApiError(mixer->api,
"%s cardid=%s cardname=%s fail to set ctlName=%s Numid=%d",
__func__, sndcard->cid.cardid, sndcard->cid.longname, ctlName, numid);
- goto OnErrorExit;
+ goto fail;
}
AFB_ApiNotice(mixer->api,
"%s cardid=%s cardname=%s ctl create name=%s numid=%d value=%ld",
- __func__, sndcard->cid.cardid, sndcard->cid.longname, ctlName, numid, value);
+
+ __func__, sndcard->cid.cardid, sndcard->cid.longname, ctlName, numid, value);
+fail:
+ free(elemId);
return numid;
-OnErrorExit:
- return -1;
+
}
STATIC int CtlSubscribeEventCB(sd_event_source* src, int fd, uint32_t revents, void* userData) {