From 074e6871959279c4aed3e162f21f677e08338b3a Mon Sep 17 00:00:00 2001 From: José Bollo Date: Fri, 29 Mar 2019 09:26:29 +0100 Subject: Fix a SIGSEGV during initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- plugins/alsa/alsa-api-loop.c | 18 ++++++++---------- 1 file 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: -- cgit 1.2.3-korg