summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAniket Kumar Lata <alata@quicinc.com>2019-10-23 15:15:26 -0700
committerHarrison Lingren <hlingren@google.com>2019-11-26 15:24:18 -0800
commit506fd42a89494c836eda69df354177affa0820f8 (patch)
tree8bfe7ea441bccda633f4c8cfb434fdb080c7b495
parent73d6b59977595c1d0a222a1656f298e7991e43b9 (diff)
downloadandroid_hardware_qcom_audio-506fd42a89494c836eda69df354177affa0820f8.tar.gz
android_hardware_qcom_audio-506fd42a89494c836eda69df354177affa0820f8.tar.bz2
android_hardware_qcom_audio-506fd42a89494c836eda69df354177affa0820f8.zip
audio: free and assign NULL to global static device pointer
Free and assign NULL to global static device pointer instead of local pointer to avoid free after use issue. Bug: 144583303 Signed-off-by: Harrison Lingren <hlingren@google.com> Change-Id: Idfdef719320efcd792c7d2ebd7ec2dfe5d3fbfbd
-rw-r--r--hal/audio_hw.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 1c99066f..17bb6f63 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -6282,12 +6282,10 @@ static int adev_verify_devices(struct audio_device *adev)
static int adev_close(hw_device_t *device)
{
size_t i;
- struct audio_device *adev_temp = (struct audio_device *)device;
-
- if (!adev_temp)
- return 0;
pthread_mutex_lock(&adev_init_lock);
+ if (!device || ((struct audio_device *)device != adev))
+ goto done;
if ((--audio_device_ref_count) == 0) {
audio_extn_snd_mon_unregister_listener(adev);
@@ -6306,10 +6304,11 @@ static int adev_close(hw_device_t *device)
adev->adm_deinit(adev->adm_data);
pthread_mutex_destroy(&adev->lock);
free(device);
+ adev = NULL;
}
+done:
pthread_mutex_unlock(&adev_init_lock);
-
return 0;
}