mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-04 22:49:13 +02:00
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:
parent
50f4a79d98
commit
0423488955
1 changed files with 10 additions and 4 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue