vulkan/wsi: Fix realloc error handling in wsi_get_modifiers_for_format

Replace assert() with proper error checking for realloc() failure.
If realloc fails, free any existing modifiers, clean up resources,
and return NULL instead of potentially crashing or leaking memory.

Fixes a potential memory leak when memory allocation fails.

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39215>
This commit is contained in:
Osama Abdelkader 2026-01-08 15:38:30 +01:00 committed by Marge Bot
parent 50f4a79d98
commit 0423488955

View file

@ -1689,10 +1689,16 @@ wsi_get_modifiers_for_format(const struct wsi_display * const wsi,
if (!(mod->formats & (1ull << (format_index - mod->offset))))
continue;
modifiers = realloc(modifiers,
(count_modifiers + 1) *
sizeof(modifiers[0]));
assert(modifiers);
uint64_t *new_modifiers = realloc(modifiers,
(count_modifiers + 1) *
sizeof(modifiers[0]));
if (!new_modifiers) {
free(modifiers);
drmModeFreePropertyBlob(blob);
drmModeFreeObjectProperties(props);
return NULL;
}
modifiers = new_modifiers;
modifiers[count_modifiers++] = mod->modifier;
}