Merge faf0bfff91f7bdcfc13ad52ddd57e267c5f1ad7a on remote branch

Change-Id: Iba64caedd1094268aa48ced5abfb802ac2ba616e
diff --git a/sound_trigger_hw.c b/sound_trigger_hw.c
index 4891b50..1d3b001 100644
--- a/sound_trigger_hw.c
+++ b/sound_trigger_hw.c
@@ -45,6 +45,8 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
+ *
+ *Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  */
 #define LOG_TAG "sound_trigger_hw"
 #define ATRACE_TAG (ATRACE_TAG_HAL)
@@ -808,7 +810,8 @@
         if (event_type == AUDIO_EVENT_CAPTURE_DEVICE_INACTIVE &&
             !platform_stdev_is_dedicated_sva_path(stdev->platform) &&
             platform_stdev_backend_reset_allowed(stdev->platform))
-            platform_stdev_disable_stale_devices(stdev->platform);
+            if (stdev->tx_concurrency_active == 0)
+                platform_stdev_disable_stale_devices(stdev->platform);
         pthread_mutex_unlock(&stdev->lock);
         return;
     }
diff --git a/sound_trigger_platform.c b/sound_trigger_platform.c
index fcab41e..03d9c96 100755
--- a/sound_trigger_platform.c
+++ b/sound_trigger_platform.c
@@ -2044,7 +2044,8 @@
     if (my_data->xml_version < PLATFORM_XML_VERSION_0x0106) {
         ALOGE("%s: Unexpected platform xml version 0x%x, exiting", __func__,
             my_data->xml_version);
-        return -EINVAL;
+        ret = -EINVAL;
+        goto err_exit;
     }
 
     /* Get the last added vendor_info node */
diff --git a/st_hw_session_lsm.c b/st_hw_session_lsm.c
index 4ffd9fd..a5de07e 100644
--- a/st_hw_session_lsm.c
+++ b/st_hw_session_lsm.c
@@ -1343,6 +1343,7 @@
     pthread_create(&p_lsm_ses->buffer_thread, &attr,
         buffer_thread_loop, p_lsm_ses);
 
+    pthread_attr_destroy(&attr);
     return status;
 
 error_exit:
diff --git a/st_session.c b/st_session.c
index e8704bc..f9d38e3 100644
--- a/st_session.c
+++ b/st_session.c
@@ -2524,7 +2524,8 @@
                 }
                 if (param_hdr->payload_size != conf_levels_payload_size) {
                     ALOGE("%s: Conf level format error, exiting", __func__);
-                    return -EINVAL;
+                    status = -EINVAL;
+                    goto ERR_EXIT;
                 }
                 status = parse_rc_config_key_conf_levels(stc_ses, st_hw_ses,
                     opaque_ptr, &conf_levels, &num_conf_levels);
@@ -2535,7 +2536,8 @@
                 if (status) {
                     ALOGE("%s: parsing conf levels failed(status=%d)",
                         __func__, status);
-                    return -EINVAL;
+                    status = -EINVAL;
+                    goto ERR_EXIT;
                 }
                 break;
             case ST_PARAM_KEY_HISTORY_BUFFER_CONFIG:
@@ -2543,7 +2545,8 @@
                     sizeof(struct st_hist_buffer_info)) {
                     ALOGE("%s: History buffer config format error, exiting",
                           __func__);
-                    return -EINVAL;
+                    status = -EINVAL;
+                    goto ERR_EXIT;
                 }
                 hist_buf = (struct st_hist_buffer_info *)(opaque_ptr +
                     sizeof(struct st_param_header));
@@ -2563,7 +2566,8 @@
                 if (param_hdr->payload_size !=
                     sizeof(struct st_det_perf_mode_info)) {
                     ALOGE("%s: Opaque data format error, exiting", __func__);
-                    return -EINVAL;
+                    status = -EINVAL;
+                    goto ERR_EXIT;
                 }
                 det_perf_mode = (struct st_det_perf_mode_info *)(opaque_ptr +
                     sizeof(struct st_param_header));
@@ -2576,7 +2580,8 @@
                 break;
             default:
                 ALOGE("%s: Unsupported opaque data key id, exiting", __func__);
-                return -EINVAL;
+                status = -EINVAL;
+                goto ERR_EXIT;
             }
         }
     } else if (stc_ses->sm_type == SOUND_MODEL_TYPE_KEYPHRASE) {
@@ -2610,7 +2615,8 @@
         stc_ses->sm_info.model_id);
     if (!sthw_cfg) {
         ALOGE("%s: Unexpected, no matching sthw_cfg", __func__);
-        return -EINVAL;
+        status = -EINVAL;
+        goto ERR_EXIT;
     }
 
     if (stc_ses->f_stage_version == ST_MODULE_TYPE_GMM) {
@@ -2634,7 +2640,8 @@
             if (num_conf_levels != stc_ses->sm_info.cf_levels_size) {
                 ALOGE("%s: Unexpected, client cf levels %d != sm_info cf levels %d",
                     __func__, num_conf_levels, stc_ses->sm_info.cf_levels_size);
-                return -EINVAL;
+                status = -EINVAL;
+                goto ERR_EXIT;
             }
 
             /*
@@ -2779,6 +2786,12 @@
           st_ses->lab_enabled);
 
     return status;
+
+ERR_EXIT:
+    if (conf_levels) {
+        free(conf_levels);
+    }
+    return status;
 }
 
 static int reg_all_sm(st_proxy_session_t *st_ses, st_hw_session_t *hw_ses)