summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVlad Zahorodnii <vlad.zahorodnii@kde.org>2020-10-10 22:04:03 +0300
committerVlad Zahorodnii <vlad.zahorodnii@kde.org>2020-10-12 14:23:23 +0300
commitc594b7622f52dea291d33757b74971b3902b5d37 (patch)
treed05cb75fde0af0c86cea881d721ec59f140e65f8
parent4d502184d2466d7861180a4ea70d60d290284988 (diff)
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 <davidedmundson@kde.org>
-rw-r--r--src/qtwaylandscanner/qtwaylandscanner.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/qtwaylandscanner/qtwaylandscanner.cpp b/src/qtwaylandscanner/qtwaylandscanner.cpp
index e984b8684..5b5694119 100644
--- a/src/qtwaylandscanner/qtwaylandscanner.cpp
+++ b/src/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");