summaryrefslogtreecommitdiffstats
path: root/plugins/alsa/alsa-api-loop.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2019-03-29 09:26:29 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2019-04-05 10:39:31 +0200
commit966189b7a6f0d4288c4c68a7c6b024577bf6b724 (patch)
tree408c6c774b143faf969694478239d3b771688241 /plugins/alsa/alsa-api-loop.c
parentb6aec989e0620322250b033bf339db7868d117d3 (diff)
Fix a SIGSEGV during initialization
During the initialisation of 4a-softmixer, when the function 'ProcessOneAvirtSubdev' fails, the function 'AttachOneLoop' was crashing because it tried to call 'snd_ctl_close' with a NULL pointer. This change fixes it. A test is introduced because depending on the kind of loop, the order of initialization of control versus subdevs differs. At the same time, some gotos are improved to avoid a dummy test -this are also virtual fixes-. Also a tiny refactor of the 3 times declared variable 'subdev' is expected to improve the readability. Bug-AGL: SPEC-2287 Change-Id: Ie5231a1064090d772ea0ea7d86ad8c8d79b38d72 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'plugins/alsa/alsa-api-loop.c')
-rw-r--r--plugins/alsa/alsa-api-loop.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/plugins/alsa/alsa-api-loop.c b/plugins/alsa/alsa-api-loop.c
index 8cf0c4e..e5e6af5 100644
--- a/plugins/alsa/alsa-api-loop.c
+++ b/plugins/alsa/alsa-api-loop.c
@@ -235,6 +235,7 @@ static void freeSubdev(SoftMixerT* mixer, AlsaLoopSubdevT * subdev) {
STATIC AlsaSndLoopT *AttachOneLoop(SoftMixerT *mixer, const char *uid, json_object *argsJ, json_object *streamsJ) {
+ AlsaLoopSubdevT * subdev;
json_object *subdevsJ = NULL, *devicesJ = NULL;
int error;
@@ -302,8 +303,6 @@ STATIC AlsaSndLoopT *AttachOneLoop(SoftMixerT *mixer, const char *uid, json_obje
}
}
- AlsaLoopSubdevT * subdev;
-
switch (json_object_get_type(subdevsJ)) {
case json_type_object:
subdev = ProcessOneSubdev(mixer, loop, subdevsJ);
@@ -334,9 +333,7 @@ STATIC AlsaSndLoopT *AttachOneLoop(SoftMixerT *mixer, const char *uid, json_obje
AFB_ApiNotice(mixer->api, "nbStreams: %d max.streams: %d", mixer->nbStreams, mixer->max.streams);
if (mixer->nbStreams >= mixer->max.streams)
- goto fail_snd_card_ctl;
-
- AlsaLoopSubdevT * subdev;
+ goto fail_snd_card;
// Create AVIRT streams
switch (json_object_get_type(streamsJ)) {
@@ -363,7 +360,7 @@ STATIC AlsaSndLoopT *AttachOneLoop(SoftMixerT *mixer, const char *uid, json_obje
break;
}
default:
- goto fail_snd_card_ctl;
+ goto fail_snd_card;
}
snd_avirt_card_seal();
@@ -381,17 +378,18 @@ STATIC AlsaSndLoopT *AttachOneLoop(SoftMixerT *mixer, const char *uid, json_obje
return loop;
-fail_loop_subdev: {
+fail_loop_subdev:
AFB_ApiDebug(mixer->api, "%s cleanup", __func__);
- AlsaLoopSubdevT * subdev, *tmp;
+ AlsaLoopSubdevT *tmp;
cds_list_for_each_entry_safe(subdev, tmp, &loop->subdevs.list, list) {
cds_list_del(&subdev->list);
freeSubdev(mixer, subdev);
}
-}
fail_snd_card_ctl:
- snd_ctl_close(loop->sndcard->ctl);
+ /* in the case of avirt, loop->sndcard->ctl may be NULL */
+ if (loop->sndcard->ctl)
+ snd_ctl_close(loop->sndcard->ctl);
fail_snd_card:
free(loop->sndcard);
fail_loop: