1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Fix use after free of NetCamView

Someone was connecting a singal to a lambda capturing this, and never disconnecting it in the destructor. Capturing this is DANGEROUS, kids, don't do this at home.
This commit is contained in:
tux3 2015-12-15 21:19:10 +01:00
parent af59b5b45a
commit e286f9673c
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
2 changed files with 14 additions and 5 deletions

View File

@ -56,16 +56,16 @@ NetCamView::NetCamView(int friendId, QWidget* parent)
frameLayout->setMargin(0); frameLayout->setMargin(0);
updateRatio(); updateRatio();
connect(selfVideoSurface, &VideoSurface::ratioChanged, this, &NetCamView::updateRatio); connections += connect(selfVideoSurface, &VideoSurface::ratioChanged, this, &NetCamView::updateRatio);
connect(videoSurface, &VideoSurface::boundaryChanged, [this]() connections += connect(videoSurface, &VideoSurface::boundaryChanged, [this]()
{ {
QRect boundingRect = videoSurface->getBoundingRect(); QRect boundingRect = videoSurface->getBoundingRect();
updateFrameSize(boundingRect.size()); updateFrameSize(boundingRect.size());
selfFrame->setBoundary(boundingRect); selfFrame->setBoundary(boundingRect);
}); });
connect(videoSurface, &VideoSurface::ratioChanged, [this]() connections += connect(videoSurface, &VideoSurface::ratioChanged, [this]()
{ {
selfFrame->setMinimumWidth(selfFrame->minimumHeight() * selfVideoSurface->getRatio()); selfFrame->setMinimumWidth(selfFrame->minimumHeight() * selfVideoSurface->getRatio());
QRect boundingRect = videoSurface->getBoundingRect(); QRect boundingRect = videoSurface->getBoundingRect();
@ -73,12 +73,12 @@ NetCamView::NetCamView(int friendId, QWidget* parent)
selfFrame->resetBoundary(boundingRect); selfFrame->resetBoundary(boundingRect);
}); });
connect(Core::getInstance(), &Core::selfAvatarChanged, [this](const QPixmap& pixmap) connections += connect(Core::getInstance(), &Core::selfAvatarChanged, [this](const QPixmap& pixmap)
{ {
selfVideoSurface->setAvatar(pixmap); selfVideoSurface->setAvatar(pixmap);
}); });
connect(Core::getInstance(), &Core::friendAvatarChanged, [this](int FriendId, const QPixmap& pixmap) connections += connect(Core::getInstance(), &Core::friendAvatarChanged, [this](int FriendId, const QPixmap& pixmap)
{ {
if (this->friendId == FriendId) if (this->friendId == FriendId)
videoSurface->setAvatar(pixmap); videoSurface->setAvatar(pixmap);
@ -92,6 +92,12 @@ NetCamView::NetCamView(int friendId, QWidget* parent)
videoMode.FPS = Settings::getInstance().getCamVideoFPS(); videoMode.FPS = Settings::getInstance().getCamVideoFPS();
} }
NetCamView::~NetCamView()
{
for (QMetaObject::Connection conn : connections)
disconnect(conn);
}
void NetCamView::show(VideoSource *source, const QString &title) void NetCamView::show(VideoSource *source, const QString &title)
{ {
setSource(source); setSource(source);

View File

@ -21,6 +21,7 @@
#define NETCAMVIEW_H #define NETCAMVIEW_H
#include "genericnetcamview.h" #include "genericnetcamview.h"
#include <QVector>
class QHBoxLayout; class QHBoxLayout;
struct vpx_image; struct vpx_image;
@ -34,6 +35,7 @@ class NetCamView : public GenericNetCamView
public: public:
NetCamView(int friendId, QWidget *parent=0); NetCamView(int friendId, QWidget *parent=0);
~NetCamView();
virtual void show(VideoSource* source, const QString& title); virtual void show(VideoSource* source, const QString& title);
virtual void hide(); virtual void hide();
@ -54,6 +56,7 @@ private:
MovableWidget* selfFrame; MovableWidget* selfFrame;
int friendId; int friendId;
bool e = false; bool e = false;
QVector<QMetaObject::Connection> connections;
}; };
#endif // NETCAMVIEW_H #endif // NETCAMVIEW_H