From 506fd42a89494c836eda69df354177affa0820f8 Mon Sep 17 00:00:00 2001 From: Aniket Kumar Lata Date: Wed, 23 Oct 2019 15:15:26 -0700 Subject: 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 Change-Id: Idfdef719320efcd792c7d2ebd7ec2dfe5d3fbfbd --- hal/audio_hw.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'hal') diff --git a/hal/audio_hw.c b/hal/audio_hw.c index 1c99066..17bb6f6 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; } -- cgit v1.2.3