hal: Fix use-after-free in clear_devices
For removing and freeing objects during list iteration,
use list_for_each_safe which prevents use-after-free
vulnerability.
CRs-Fixed: 2648712
Change-Id: Ibecc08e16f009feb585f510a7b0cc3bb8957897b
diff --git a/hal/audio_extn/device_utils.c b/hal/audio_extn/device_utils.c
index 7bc4150..a0ee5b5 100644
--- a/hal/audio_extn/device_utils.c
+++ b/hal/audio_extn/device_utils.c
@@ -337,13 +337,13 @@
int clear_devices(struct listnode *devices)
{
- struct listnode *node;
+ struct listnode *node, *temp;
struct audio_device_info *item = NULL;
if (devices == NULL)
return 0;
- list_for_each (node, devices) {
+ list_for_each_safe (node, temp, devices) {
item = node_to_item(node, struct audio_device_info, list);
if (item != NULL) {
list_remove(&item->list);