From 451d65660b62aa23e9d3083174153e9a5a068c5f Mon Sep 17 00:00:00 2001 From: Fulup Ar Foll Date: Thu, 2 Nov 2017 21:50:09 +0100 Subject: Fix FD leaking on Alsa Control --- alsa-binding/Alsa-RegEvt.c | 5 ++- alsa-binding/Alsa-SetGet.c | 4 +- alsa-binding/Alsa-Ucm.c | 2 +- nbproject/configurations.xml | 88 ++++++++++++++++++-------------------------- 4 files changed, 44 insertions(+), 55 deletions(-) diff --git a/alsa-binding/Alsa-RegEvt.c b/alsa-binding/Alsa-RegEvt.c index 41db207..035806e 100644 --- a/alsa-binding/Alsa-RegEvt.c +++ b/alsa-binding/Alsa-RegEvt.c @@ -235,8 +235,9 @@ PUBLIC void alsaEvtSubcribe(afb_req request) { // increase usage count and return success sndHandles[idx].ucount++; + snd_ctl_close(ctlDev); afb_req_success(request, NULL, NULL); - return; + // use OnErrorExit OnErrorExit: if (ctlDev) snd_ctl_close(ctlDev); @@ -277,6 +278,8 @@ STATIC json_object *alsaProbeCardId(afb_req request) { shortname = snd_ctl_card_info_get_name(cardinfo); longname = snd_ctl_card_info_get_longname(cardinfo); + snd_ctl_close(ctlDev); + // check if short|long name match if (!strcmp(sndname, ctlName)) break; if (!strcmp(sndname, shortname)) break; diff --git a/alsa-binding/Alsa-SetGet.c b/alsa-binding/Alsa-SetGet.c index 2083a53..1b7d4a8 100644 --- a/alsa-binding/Alsa-SetGet.c +++ b/alsa-binding/Alsa-SetGet.c @@ -655,7 +655,7 @@ STATIC void alsaSetGetCtls(ActionSetGetT action, afb_req request) { const char *warmsg = NULL; int err = 0, status = 0, done; unsigned int ctlCount; - snd_ctl_t *ctlDev; + snd_ctl_t *ctlDev=NULL; snd_ctl_elem_list_t *ctlList; queryValuesT queryValues; json_object *queryJ, *numidsJ, *sndctls; @@ -799,8 +799,10 @@ STATIC void alsaSetGetCtls(ActionSetGetT action, afb_req request) { // send response+warning if any afb_req_success(request, sndctls, warmsg); snd_ctl_elem_list_clear(ctlList); + // use OnErrorExit OnErrorExit: + if (ctlDev) snd_ctl_close(ctlDev); return; } diff --git a/alsa-binding/Alsa-Ucm.c b/alsa-binding/Alsa-Ucm.c index 0bfffc9..d608e61 100644 --- a/alsa-binding/Alsa-Ucm.c +++ b/alsa-binding/Alsa-Ucm.c @@ -52,7 +52,7 @@ static ucmHandleT ucmHandles[MAX_SND_CARD]; // Cache opened UCM handles STATIC int alsaUseCaseOpen(struct afb_req request, queryValuesT *queryValues, int allowNewMgr) { - snd_ctl_t *ctlDev; + snd_ctl_t *ctlDev=NULL; snd_ctl_card_info_t *cardinfo; snd_use_case_mgr_t *ucmHandle; const char *cardName; diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 78905c4..85f3fef 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -464,81 +464,57 @@ - - - ../../../opt/include/afb - alsa-binding - ../../../opt/include/alsa - /usr/include/json-c - ../../../opt/include - build/alsa-binding - + + + + + + + + + + + + + + + + + /usr/include/json-c ../../../opt/include /usr/include/p11-kit-1 ../../../opt/include/alsa - afb-utilities - build/alsa-binding + build/alsa-hook CONTROL_MAXPATH_LEN=255 MAX_LINEAR_DB_SCALE=24 MAX_SND_CARD=16 NATIVE_LINUX + PIC TLV_BYTE_SIZE=256 - alsa_4a_EXPORTS + policy_alsa_hook_EXPORTS - - - - ../../../opt/include/afb - alsa-binding - ../../../opt/include/alsa - /usr/include/json-c - ../../../opt/include - build/alsa-binding - - - - + - ../../../opt/include/afb - alsa-binding + alsa-hook ../../../opt/include/alsa /usr/include/json-c - ../../../opt/include - build/alsa-binding - - - - - - ../../../opt/include/afb - alsa-binding - ../../../opt/include/alsa - /usr/include/json-c ../../../opt/include - build/alsa-binding + build/alsa-hook - - - - - - - - @@ -766,16 +742,24 @@ - + - alsa-hook - ../../../opt/include/alsa /usr/include/json-c - ../../../opt/include/afb ../../../opt/include - build/alsa-hook + /usr/include/p11-kit-1 + ../../../opt/include/alsa + afb-utilities + build/alsa-binding + + CONTROL_MAXPATH_LEN=255 + MAX_LINEAR_DB_SCALE=24 + MAX_SND_CARD=16 + NATIVE_LINUX + TLV_BYTE_SIZE=256 + alsa_4a_EXPORTS + -- cgit 1.2.3-korg