summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVlad Zahorodnii <vlad.zahorodnii@kde.org>2020-10-10 22:04:03 +0300
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-10-12 12:00:09 +0000
commit407c240bf52f0c5d23cd87be48ced51a58562f19 (patch)
tree34e8ec8483e16143767b895efe97d8024724ace8
parent65922085c3ba302b9049e62c1e132236b726adf9 (diff)
downloadqtwayland-407c240bf52f0c5d23cd87be48ced51a58562f19.tar.gz
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. Change-Id: I82dab3b7eae8c282fdbad689af49622350b6c867 Reviewed-by: David Edmundson <davidedmundson@kde.org> (cherry picked from commit c594b7622f52dea291d33757b74971b3902b5d37) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.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 3cecb5bc..41e8126e 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");