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
This commit is contained in:
Vlad Zahorodnii 2021-09-24 20:09:27 +03:00
parent ba0d099e38
commit 48d9e4cc0e

View file

@ -487,6 +487,9 @@ bool Scanner::process()
printf("#include <QMultiMap>\n");
printf("#include <QString>\n");
printf("\n");
printf("#include <unistd.h>\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");