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

Thanks to build.kde.org for detecting and reporting this issue.
This commit is contained in:
Martin Flöser 2017-12-03 18:01:43 +01:00
parent 545dda7208
commit 724ecaf1e9
2 changed files with 13 additions and 2 deletions

View file

@ -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)

View file

@ -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;
};
}