util: do not access member of a NULL structure

Check if the structure is NULL before trying to get access to its
members.

This has been detected by the Undefined Behaviour Sanitizer (UBSan).

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29772>
This commit is contained in:
Juan A. Suarez Romero 2024-06-18 17:20:18 +02:00 committed by Marge Bot
parent d854dd32fb
commit d4dcbaf825

View file

@ -128,7 +128,8 @@ pipe_surface_release(struct pipe_context *pipe, struct pipe_surface **ptr)
{
struct pipe_surface *old = *ptr;
if (pipe_reference_described(&old->reference, NULL,
if (pipe_reference_described(old ? &old->reference : NULL,
NULL,
(debug_reference_descriptor)
debug_describe_surface))
pipe->surface_destroy(pipe, old);