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:
parent
af59b5b45a
commit
e286f9673c
|
@ -56,16 +56,16 @@ NetCamView::NetCamView(int friendId, QWidget* parent)
|
|||
frameLayout->setMargin(0);
|
||||
|
||||
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();
|
||||
updateFrameSize(boundingRect.size());
|
||||
selfFrame->setBoundary(boundingRect);
|
||||
});
|
||||
|
||||
connect(videoSurface, &VideoSurface::ratioChanged, [this]()
|
||||
connections += connect(videoSurface, &VideoSurface::ratioChanged, [this]()
|
||||
{
|
||||
selfFrame->setMinimumWidth(selfFrame->minimumHeight() * selfVideoSurface->getRatio());
|
||||
QRect boundingRect = videoSurface->getBoundingRect();
|
||||
|
@ -73,12 +73,12 @@ NetCamView::NetCamView(int friendId, QWidget* parent)
|
|||
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);
|
||||
});
|
||||
|
||||
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)
|
||||
videoSurface->setAvatar(pixmap);
|
||||
|
@ -92,6 +92,12 @@ NetCamView::NetCamView(int friendId, QWidget* parent)
|
|||
videoMode.FPS = Settings::getInstance().getCamVideoFPS();
|
||||
}
|
||||
|
||||
NetCamView::~NetCamView()
|
||||
{
|
||||
for (QMetaObject::Connection conn : connections)
|
||||
disconnect(conn);
|
||||
}
|
||||
|
||||
void NetCamView::show(VideoSource *source, const QString &title)
|
||||
{
|
||||
setSource(source);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#define NETCAMVIEW_H
|
||||
|
||||
#include "genericnetcamview.h"
|
||||
#include <QVector>
|
||||
|
||||
class QHBoxLayout;
|
||||
struct vpx_image;
|
||||
|
@ -34,6 +35,7 @@ class NetCamView : public GenericNetCamView
|
|||
|
||||
public:
|
||||
NetCamView(int friendId, QWidget *parent=0);
|
||||
~NetCamView();
|
||||
|
||||
virtual void show(VideoSource* source, const QString& title);
|
||||
virtual void hide();
|
||||
|
@ -54,6 +56,7 @@ private:
|
|||
MovableWidget* selfFrame;
|
||||
int friendId;
|
||||
bool e = false;
|
||||
QVector<QMetaObject::Connection> connections;
|
||||
};
|
||||
|
||||
#endif // NETCAMVIEW_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user