summaryrefslogtreecommitdiffstats
path: root/plugins
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-03-29 09:40:26 +0000
commit074e6871959279c4aed3e162f21f677e08338b3a (patch)
treeb7031cd5f616deaf51e7f25c78106630f423607c /plugins
parent943f34b1d319e0ddc157dcfd85acde628f9d2ead (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')
-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 c9456f2..7949c63 100644
--- a/plugins/alsa/alsa-api-loop.c
+++ b/plugins/alsa/alsa-api-loop.c
@@ -236,6 +236,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;
@@ -303,8 +304,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);
@@ -335,9 +334,7 @@ STATIC AlsaSndLoopT *AttachOneLoop(SoftMixerT *mixer, const char *uid, json_obje
AFB_API_NOTICE(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)) {
@@ -364,7 +361,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();
@@ -382,17 +379,18 @@ STATIC AlsaSndLoopT *AttachOneLoop(SoftMixerT *mixer, const char *uid, json_obje
return loop;
-fail_loop_subdev: {
+fail_loop_subdev:
AFB_API_DEBUG(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: