From 6aafb58432331392afeebf074a337565f2f05b64 Mon Sep 17 00:00:00 2001 From: "Juan A. Suarez Romero" Date: Tue, 27 Aug 2024 20:44:18 +0200 Subject: [PATCH] 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 Signed-off-by: Juan A. Suarez Romero Part-of: --- src/gallium/drivers/virgl/tests/virgl_staging_mgr_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/virgl/tests/virgl_staging_mgr_test.cpp b/src/gallium/drivers/virgl/tests/virgl_staging_mgr_test.cpp index 057445a7718..0a5a2464832 100644 --- a/src/gallium/drivers/virgl/tests/virgl_staging_mgr_test.cpp +++ b/src/gallium/drivers/virgl/tests/virgl_staging_mgr_test.cpp @@ -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); }