From e956efdcfa0d453fbbd40493c3e84d144cedd250 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Sat, 10 Oct 2020 22:04:03 +0300 Subject: [PATCH] Scanner: Generate code that cleans up m_resource The object that owns the resource will not be necessarily destroyed in the destroy_resource() function. One such case may arise if the compositor wants to animate the disappearing of a window, in that case we want to keep client buffer data around even after the wl_buffer resource has been destroyed. If the compositor accidentally accesses the destroyed resource, it'll most likely crash because of SIGSEGV. Speaking from my experience, such crashes are far from being fun to debug. With this change, qtwaylandscanner will generate code that cleans up m_resource when the associated resource has been destroyed. It can be useful for the purpose of preventing accessing already destroyed data. Note that we want m_resource to be valid when the destroy_resource() func is called because the compositor may need it in order to properly perform cleanup, for example send a wl_pointer::leave() event, etc. Pick-to: 5.15 Change-Id: I82dab3b7eae8c282fdbad689af49622350b6c867 Reviewed-by: David Edmundson --- src/tools/qtwaylandscanner/qtwaylandscanner.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tools/qtwaylandscanner/qtwaylandscanner.cpp b/src/tools/qtwaylandscanner/qtwaylandscanner.cpp index e984b8684ee..5b569411931 100644 --- a/src/tools/qtwaylandscanner/qtwaylandscanner.cpp +++ b/src/tools/qtwaylandscanner/qtwaylandscanner.cpp @@ -810,6 +810,8 @@ bool Scanner::process() printf(" %s *that = resource->%s_object;\n", interfaceName, interfaceNameStripped); printf(" that->m_resource_map.remove(resource->client(), resource);\n"); printf(" that->%s_destroy_resource(resource);\n", interfaceNameStripped); + printf(" if (that->m_resource == resource)\n"); + printf(" that->m_resource = nullptr;\n"); printf(" delete resource;\n"); printf(" }\n"); printf("\n");