hal: Fix adev_open error handling
Change error handling in adev_open to correctly
set adev pointer to NULL after freeing memory and
destroy adev mutex before freeing adev memory. If
adev pointer is not set to NULL any calls made
into ahal will pass NULL checks and access freed
memory causing multiple issues such as segmentation
for locking a freed adev mutex.
Change-Id: I3cf35999d09418be3bb0c888d620eae18831a153
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 0816aa8..70ccadc 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -7308,23 +7308,25 @@
/* Loads platform specific libraries dynamically */
adev->platform = platform_init(adev);
if (!adev->platform) {
+ pthread_mutex_destroy(&adev->lock);
free(adev->snd_dev_ref_cnt);
free(adev);
+ adev = NULL;
ALOGE("%s: Failed to init platform data, aborting.", __func__);
*device = NULL;
pthread_mutex_unlock(&adev_init_lock);
- pthread_mutex_destroy(&adev->lock);
return -EINVAL;
}
if (audio_extn_qaf_is_enabled()) {
ret = audio_extn_qaf_init(adev);
if (ret < 0) {
+ pthread_mutex_destroy(&adev->lock);
free(adev);
+ adev = NULL;
ALOGE("%s: Failed to init platform data, aborting.", __func__);
*device = NULL;
pthread_mutex_unlock(&adev_init_lock);
- pthread_mutex_destroy(&adev->lock);
return ret;
}