Commit 724ecaf1 authored by Martin Flöser's avatar Martin Flöser

Fix possible heap-use-after-free in idle inhibition handling

Thanks to build.kde.org for detecting and reporting this issue.
parent 545dda72
......@@ -42,7 +42,7 @@ IdleInhibition::~IdleInhibition() = default;
void IdleInhibition::registerShellClient(ShellClient *client)
{
auto surface = client->surface();
connect(surface, &SurfaceInterface::inhibitsIdleChanged, this,
m_connections.insert(client, connect(surface, &SurfaceInterface::inhibitsIdleChanged, this,
[this, client] {
// TODO: only inhibit if the ShellClient is visible
if (client->surface()->inhibitsIdle()) {
......@@ -51,8 +51,17 @@ void IdleInhibition::registerShellClient(ShellClient *client)
uninhibit(client);
}
}
));
connect(client, &ShellClient::windowClosed, this,
[this, client] {
uninhibit(client);
auto it = m_connections.find(client);
if (it != m_connections.end()) {
disconnect(it.value());
m_connections.erase(it);
}
}
);
connect(client, &ShellClient::windowClosed, this, std::bind(&IdleInhibition::uninhibit, this, client));
}
void IdleInhibition::inhibit(ShellClient *client)
......
......@@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QObject>
#include <QVector>
#include <QMap>
#include <algorithm>
......@@ -60,5 +61,6 @@ private:
IdleInterface *m_idle;
QVector<ShellClient*> m_idleInhibitors;
QMap<ShellClient*, QMetaObject::Connection> m_connections;
};
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment