virgl: fix member access to a NULL pointer struct

This fixes VirglStagingMgr tests that tries to access a struct member of
a structure that is NULL.

This has been detected using Undefined Behaviour Sanitizer.

```
Running main() from ../src/gtest/src/gtest_main.cc
[==========] Running 9 tests from 2 test suites.
[----------] Global test environment set-up.
[----------] 7 tests from VirglStagingMgr
[ RUN      ] VirglStagingMgr.non_fitting_allocation_reallocates_resource
stderr:
../src/gallium/drivers/virgl/tests/virgl_staging_mgr_test.cpp:72:22: runtime error: member access within null pointer of type 'struct virgl_hw_res'
```

Reviewed-by: Eric Engestrom <eric@igalia.com>
Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30880>
This commit is contained in:
Juan A. Suarez Romero 2024-08-27 20:44:18 +02:00 committed by Marge Bot
parent e54a15f700
commit 6aafb58432

View file

@ -69,7 +69,8 @@ fake_resource_reference(struct virgl_winsys *vws,
{
struct virgl_hw_res *old = *dres;
if (pipe_reference(&(*dres)->reference, &sres->reference)) {
if (pipe_reference(old ? &old->reference : NULL,
sres ? &sres->reference : NULL)) {
FREE(old->data);
FREE(old);
}