Fix memory leak.
authorMateusz Przybylski <mprzybyl@google.com>
Thu, 1 Feb 2024 01:03:32 +0000 (17:03 -0800)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Thu, 1 Feb 2024 18:17:37 +0000 (11:17 -0700)
If we never find any other device after already_enumerated is recognized, the memory allocated in this function will never be freed.

loader/loader_windows.c

index 5b0dfb0dab70fae51f5f87d1ccfaf2d8e5eb5ea4..580ea68be5f04a50c13cd6db627afca167c38402 100644 (file)
@@ -860,6 +860,11 @@ VkResult enumerate_adapter_physical_devices(struct loader_instance *inst, struct
         next_icd_phys_devs->icd_term = icd_term;
         next_icd_phys_devs->windows_adapter_luid = luid;
         (*icd_phys_devs_array_count)++;
+    } else {
+        // Avoid memory leak in case of the already_enumerated hitting true
+        // at the last enumerate_adapter_physical_devices call in the outer loop
+        loader_instance_heap_free(inst, next_icd_phys_devs->physical_devices);
+        next_icd_phys_devs->physical_devices = NULL;
     }
 
     return VK_SUCCESS;