From af42f2204c61f7f044f8d06b7cad9bb79cf8f5e0 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Thu, 18 Feb 2021 15:04:03 +0900 Subject: [PATCH] Fix SVACE defect (DEREF_OF_NULL.RET.ALLOC) [Version] 0.1.12 [Issue Type] Svace Change-Id: I3b99addff886186521c246f73eae05eb07473f29 --- packaging/audio-hal-wm1831-tw2.spec | 2 +- tizen-audio-impl-ucm.c | 49 ++++++++++------------------- 2 files changed, 18 insertions(+), 33 deletions(-) diff --git a/packaging/audio-hal-wm1831-tw2.spec b/packaging/audio-hal-wm1831-tw2.spec index 2e82c2b..98ba93f 100644 --- a/packaging/audio-hal-wm1831-tw2.spec +++ b/packaging/audio-hal-wm1831-tw2.spec @@ -1,6 +1,6 @@ Name: audio-hal-wm1831-tw2 Summary: TIZEN Audio HAL for WM1831(TW2) -Version: 0.1.11 +Version: 0.1.12 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/tizen-audio-impl-ucm.c b/tizen-audio-impl-ucm.c index 7ff7cbc..094ee4f 100644 --- a/tizen-audio-impl-ucm.c +++ b/tizen-audio-impl-ucm.c @@ -24,6 +24,7 @@ #include #include #include +#include #ifdef ALSA_UCM_DEBUG_TIME #include #include @@ -170,28 +171,20 @@ audio_return_t _ucm_set_use_case(audio_hal_t *ah, const char *verb, const char * AUDIO_LOG_DEBUG("current verb and new verb is same. No need to change verb, disable devices explicitely"); if (old_dev_count > 0) { - dis_dev_list = (const char **)malloc(sizeof(const char *) * old_dev_count); - for (i = 0; i < old_dev_count; i++) { - dis_dev_list[i] = NULL; - } + dis_dev_list = (const char **)calloc(old_dev_count, sizeof(const char *)); + assert(dis_dev_list); } if (dev_count > 0) { - ena_dev_list = (const char **)malloc(sizeof(const char *) * dev_count); - for (i = 0; i < dev_count; i++) { - ena_dev_list[i] = NULL; - } + ena_dev_list = (const char **)calloc(dev_count, sizeof(const char *)); + assert(ena_dev_list); } if (old_mod_count > 0) { - dis_mod_list = (const char **)malloc(sizeof(const char *) * old_mod_count); - for (i = 0; i < old_mod_count; i++) { - dis_mod_list[i] = NULL; - } + dis_mod_list = (const char **)calloc(old_mod_count, sizeof(const char *)); + assert(dis_mod_list); } if (mod_count > 0) { - ena_mod_list = (const char **)malloc(sizeof(const char *) * mod_count); - for (i = 0; i < mod_count; i++) { - ena_mod_list[i] = NULL; - } + ena_mod_list = (const char **)calloc(mod_count, sizeof(const char *)); + assert(ena_mod_list); } /* update disable modifiers list which are not present in new modifier list */ @@ -390,16 +383,12 @@ audio_return_t _ucm_set_devices(audio_hal_t *ah, const char *verb, const char *d AUDIO_LOG_DEBUG("current verb and new verb is same. No need to change verb, disable devices explicitely"); if (old_dev_count > 0) { - dis_dev_list = (const char **)malloc(sizeof(const char *) * old_dev_count); - for (i = 0; i < old_dev_count; i++) { - dis_dev_list[i] = NULL; - } + dis_dev_list = (const char **)calloc(old_dev_count, sizeof(const char *)); + assert(dis_dev_list); } if (dev_count > 0) { - ena_dev_list = (const char **)malloc(sizeof(const char *) * dev_count); - for (i = 0; i < dev_count; i++) { - ena_dev_list[i] = NULL; - } + ena_dev_list = (const char **)calloc(dev_count, sizeof(const char *)); + assert(ena_dev_list); } /* update disable devices list which are not present in new device list */ @@ -525,16 +514,12 @@ audio_return_t _ucm_set_modifiers(audio_hal_t *ah, const char *verb, const char AUDIO_LOG_DEBUG("current verb and new verb is same. No need to change verb, disable devices explicitely"); if (old_mod_count > 0) { - dis_mod_list = (const char **)malloc(sizeof(const char *) * old_mod_count); - for (i = 0; i < old_mod_count; i++) { - dis_mod_list[i] = NULL; - } + dis_mod_list = (const char **)calloc(old_mod_count, sizeof(const char *)); + assert(dis_mod_list); } if (mod_count > 0) { - ena_mod_list = (const char **)malloc(sizeof(const char *) * mod_count); - for (i = 0; i < mod_count; i++) { - ena_mod_list[i] = NULL; - } + ena_mod_list = (const char **)calloc(mod_count, sizeof(const char *)); + assert(ena_mod_list); } /* update disable modifiers list which are not present in new modifier list */ -- 2.34.1