From 141046585d180d003631bd094eae71d38f44aae1 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Sun, 7 Jan 2024 12:25:05 +0000 Subject: [PATCH] c/main: Don't use list of display if we fail to allocate it --- src/xrt/compositor/main/comp_window_direct_nvidia.c | 9 +++++++-- src/xrt/compositor/main/comp_window_direct_randr.c | 7 ++++++- src/xrt/compositor/main/comp_window_vk_display.c | 7 ++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/xrt/compositor/main/comp_window_direct_nvidia.c b/src/xrt/compositor/main/comp_window_direct_nvidia.c index 65a8c7f98..95c12335b 100644 --- a/src/xrt/compositor/main/comp_window_direct_nvidia.c +++ b/src/xrt/compositor/main/comp_window_direct_nvidia.c @@ -177,8 +177,13 @@ append_nvidia_entry_on_match(struct comp_window_direct_nvidia *w, U_ARRAY_REALLOC_OR_FREE(w->displays, struct comp_window_direct_nvidia_display, w->display_count); - if (w->displays == NULL) - COMP_ERROR(w->base.base.c, "Unable to reallocate randr_displays"); + if (w->displays == NULL) { + COMP_ERROR(w->base.base.c, "Unable to reallocate NVIDIA displays"); + + // Reset the count. + w->display_count = 0; + return false; + } w->displays[w->display_count - 1] = d; diff --git a/src/xrt/compositor/main/comp_window_direct_randr.c b/src/xrt/compositor/main/comp_window_direct_randr.c index e1dc4ae77..f6f9a727a 100644 --- a/src/xrt/compositor/main/comp_window_direct_randr.c +++ b/src/xrt/compositor/main/comp_window_direct_randr.c @@ -345,9 +345,14 @@ append_randr_display(struct comp_window_direct_randr *w, U_ARRAY_REALLOC_OR_FREE(w->displays, struct comp_window_direct_randr_display, w->display_count); - if (w->displays == NULL) + if (w->displays == NULL) { COMP_ERROR(w->base.base.c, "Unable to reallocate randr_displays"); + // Reset the count. + w->display_count = 0; + return; + } + w->displays[w->display_count - 1] = d; } diff --git a/src/xrt/compositor/main/comp_window_vk_display.c b/src/xrt/compositor/main/comp_window_vk_display.c index 708316c4b..01631b261 100644 --- a/src/xrt/compositor/main/comp_window_vk_display.c +++ b/src/xrt/compositor/main/comp_window_vk_display.c @@ -141,9 +141,14 @@ append_vk_display_entry(struct comp_window_vk_display *w, struct VkDisplayProper U_ARRAY_REALLOC_OR_FREE(w->displays, struct vk_display, w->display_count); - if (w->displays == NULL) + if (w->displays == NULL) { COMP_ERROR(w->base.base.c, "Unable to reallocate vk_display displays"); + // Reset the count. + w->display_count = 0; + return false; + } + w->displays[w->display_count - 1] = d; return true;