From 48d9e4cc0e55741492b91aa641adcf4be019b9b6 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Fri, 24 Sep 2021 20:09:27 +0300 Subject: [PATCH] Automatically close fds for inert resources If the plasma window resource is inert, the associated get_icon handler won't be invoked. This results in leaked file descriptors. With this change, the corresponding close() function call will be generated to avoid leaking file descriptors and potentially crashing the session due to kwin running out of fds. BUG: 438097 --- src/wayland/tools/qtwaylandscanner.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/wayland/tools/qtwaylandscanner.cpp b/src/wayland/tools/qtwaylandscanner.cpp index 165c2508b3..287822fc98 100644 --- a/src/wayland/tools/qtwaylandscanner.cpp +++ b/src/wayland/tools/qtwaylandscanner.cpp @@ -487,6 +487,9 @@ bool Scanner::process() printf("#include \n"); printf("#include \n"); + printf("\n"); + printf("#include \n"); + printf("\n"); printf("#ifndef WAYLAND_VERSION_CHECK\n"); printf("#define WAYLAND_VERSION_CHECK(major, minor, micro) \\\n"); @@ -946,6 +949,10 @@ bool Scanner::process() printf(" Q_UNUSED(client);\n"); printf(" Resource *r = Resource::fromResource(resource);\n"); printf(" if (Q_UNLIKELY(!r->%s_object)) {\n", interfaceNameStripped); + for (const WaylandArgument &a : e.arguments) { + if (a.type == QByteArrayLiteral("fd")) + printf(" close(%s);\n", a.name.constData()); + } if (e.type == "destructor") printf(" wl_resource_destroy(resource);\n"); printf(" return;\n");