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

Fix some memory leaks and mismatches

This commit is contained in:
tux3 2015-05-09 22:35:58 +02:00
parent bb5f2e066d
commit a01e0db7ba
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
10 changed files with 51 additions and 19 deletions

View File

@ -1248,7 +1248,7 @@ QString Core::getFriendUsername(uint32_t friendnumber) const
uint8_t* name = new uint8_t[namesize]; uint8_t* name = new uint8_t[namesize];
tox_friend_get_name(tox, friendnumber, name, nullptr); tox_friend_get_name(tox, friendnumber, name, nullptr);
QString sname = CString::toString(name, namesize); QString sname = CString::toString(name, namesize);
delete name; delete[] name;
return sname; return sname;
} }

View File

@ -21,6 +21,11 @@ QRWidget::QRWidget(QWidget *parent) : QWidget(parent), data("0")
image = new QImage(size, QImage::Format_RGB32); image = new QImage(size, QImage::Format_RGB32);
} }
QRWidget::~QRWidget()
{
delete image;
}
void QRWidget::setQRData(const QString& data) void QRWidget::setQRData(const QString& data)
{ {
this->data = data; this->data = data;

View File

@ -11,6 +11,7 @@ class QRWidget : public QWidget
public: public:
explicit QRWidget(QWidget *parent = 0); explicit QRWidget(QWidget *parent = 0);
~QRWidget();
void setQRData(const QString& data); void setQRData(const QString& data);
QImage* getImage(); QImage* getImage();
bool saveImage(QString path); bool saveImage(QString path);

View File

@ -69,7 +69,7 @@ ChatForm::ChatForm(Friend* chatFriend)
typingTimer.setSingleShot(true); typingTimer.setSingleShot(true);
netcam = new NetCamView(); netcam = nullptr;
callDurationTimer = nullptr; callDurationTimer = nullptr;
disableCallButtonsTimer = nullptr; disableCallButtonsTimer = nullptr;
@ -307,7 +307,7 @@ void ChatForm::onAvStart(uint32_t FriendId, int CallId, bool video)
connect(videoButton, SIGNAL(clicked()), connect(videoButton, SIGNAL(clicked()),
this, SLOT(onHangupCallTriggered())); this, SLOT(onHangupCallTriggered()));
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getDisplayedName()); showNetcam();
} }
else else
{ {
@ -349,7 +349,7 @@ void ChatForm::onAvCancel(uint32_t FriendId, int)
enableCallButtons(); enableCallButtons();
stopCounter(); stopCounter();
netcam->hide(); hideNetcam();
addSystemInfoMessage(tr("%1 stopped calling").arg(f->getDisplayedName()), ChatMessage::INFO, QDateTime::currentDateTime()); addSystemInfoMessage(tr("%1 stopped calling").arg(f->getDisplayedName()), ChatMessage::INFO, QDateTime::currentDateTime());
} }
@ -366,7 +366,7 @@ void ChatForm::onAvEnd(uint32_t FriendId, int)
enableCallButtons(); enableCallButtons();
stopCounter(); stopCounter();
netcam->hide(); hideNetcam();
} }
void ChatForm::onAvRinging(uint32_t FriendId, int CallId, bool video) void ChatForm::onAvRinging(uint32_t FriendId, int CallId, bool video)
@ -424,7 +424,7 @@ void ChatForm::onAvStarting(uint32_t FriendId, int CallId, bool video)
videoButton->setToolTip(tr("End video call")); videoButton->setToolTip(tr("End video call"));
connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered())); connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getDisplayedName()); showNetcam();
} }
else else
{ {
@ -453,7 +453,7 @@ void ChatForm::onAvEnding(uint32_t FriendId, int)
enableCallButtons(); enableCallButtons();
stopCounter(); stopCounter();
netcam->hide(); hideNetcam();
} }
void ChatForm::onAvRequestTimeout(uint32_t FriendId, int) void ChatForm::onAvRequestTimeout(uint32_t FriendId, int)
@ -469,7 +469,7 @@ void ChatForm::onAvRequestTimeout(uint32_t FriendId, int)
enableCallButtons(); enableCallButtons();
stopCounter(); stopCounter();
netcam->hide(); hideNetcam();
} }
void ChatForm::onAvPeerTimeout(uint32_t FriendId, int) void ChatForm::onAvPeerTimeout(uint32_t FriendId, int)
@ -485,7 +485,7 @@ void ChatForm::onAvPeerTimeout(uint32_t FriendId, int)
enableCallButtons(); enableCallButtons();
stopCounter(); stopCounter();
netcam->hide(); hideNetcam();
} }
void ChatForm::onAvRejected(uint32_t FriendId, int) void ChatForm::onAvRejected(uint32_t FriendId, int)
@ -502,7 +502,7 @@ void ChatForm::onAvRejected(uint32_t FriendId, int)
insertChatMessage(ChatMessage::createChatInfoMessage(tr("Call rejected"), ChatMessage::INFO, QDateTime::currentDateTime())); insertChatMessage(ChatMessage::createChatInfoMessage(tr("Call rejected"), ChatMessage::INFO, QDateTime::currentDateTime()));
netcam->hide(); hideNetcam();
} }
void ChatForm::onAvMediaChange(uint32_t FriendId, int CallId, bool video) void ChatForm::onAvMediaChange(uint32_t FriendId, int CallId, bool video)
@ -513,9 +513,9 @@ void ChatForm::onAvMediaChange(uint32_t FriendId, int CallId, bool video)
qDebug() << "onAvMediaChange"; qDebug() << "onAvMediaChange";
if (video) if (video)
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getDisplayedName()); showNetcam();
else else
netcam->hide(); hideNetcam();
} }
void ChatForm::onAnswerCallTriggered() void ChatForm::onAnswerCallTriggered()
@ -538,7 +538,7 @@ void ChatForm::onHangupCallTriggered()
qDebug() << "onHangupCallTriggered"; qDebug() << "onHangupCallTriggered";
//Fixes an OS X bug with ending a call while in full screen //Fixes an OS X bug with ending a call while in full screen
if (netcam->isFullScreen()) if (netcam && netcam->isFullScreen())
netcam->showNormal(); netcam->showNormal();
audioInputFlag = false; audioInputFlag = false;
@ -606,7 +606,7 @@ void ChatForm::onCancelCallTriggered()
enableCallButtons(); enableCallButtons();
netcam->hide(); hideNetcam();
emit cancelCall(callId, f->getFriendID()); emit cancelCall(callId, f->getFriendID());
} }
@ -1035,3 +1035,19 @@ void ChatForm::SendMessageStr(QString msg)
msgEdit->setLastMessage(msg); //set last message only when sending it msgEdit->setLastMessage(msg); //set last message only when sending it
} }
} }
void ChatForm::showNetcam()
{
if (!netcam)
netcam = new NetCamView();
netcam->show(Core::getInstance()->getVideoSourceFromCall(callId), f->getDisplayedName());
}
void ChatForm::hideNetcam()
{
if (!netcam)
return;
netcam->hide();
delete netcam;
netcam = nullptr;
}

View File

@ -99,6 +99,8 @@ private slots:
void doScreenshot(); void doScreenshot();
protected: protected:
void showNetcam();
void hideNetcam();
// drag & drop // drag & drop
void dragEnterEvent(QDragEnterEvent* ev); void dragEnterEvent(QDragEnterEvent* ev);
void dropEvent(QDropEvent* ev); void dropEvent(QDropEvent* ev);

View File

@ -49,7 +49,7 @@ void ProfileForm::refreshProfiles()
} }
ProfileForm::ProfileForm(QWidget *parent) : ProfileForm::ProfileForm(QWidget *parent) :
QWidget(parent) QWidget{parent}, qr{nullptr}
{ {
bodyUI = new Ui::IdentitySettings; bodyUI = new Ui::IdentitySettings;
bodyUI->setupUi(this); bodyUI->setupUi(this);
@ -132,6 +132,7 @@ ProfileForm::ProfileForm(QWidget *parent) :
ProfileForm::~ProfileForm() ProfileForm::~ProfileForm()
{ {
delete qr;
delete bodyUI; delete bodyUI;
head->deleteLater(); head->deleteLater();
} }
@ -182,6 +183,7 @@ void ProfileForm::setToxId(const QString& id)
toxId->setText(id); toxId->setText(id);
toxId->setCursorPosition(0); toxId->setCursorPosition(0);
delete qr;
qr = new QRWidget(); qr = new QRWidget();
qr->setQRData("tox:"+id); qr->setQRData("tox:"+id);
bodyUI->qrCode->setPixmap(QPixmap::fromImage(qr->getImage()->scaledToWidth(150))); bodyUI->qrCode->setPixmap(QPixmap::fromImage(qr->getImage()->scaledToWidth(150)));

View File

@ -26,6 +26,11 @@ MaskablePixmapWidget::MaskablePixmapWidget(QWidget *parent, QSize size, QString
setSize(size); setSize(size);
} }
MaskablePixmapWidget::~MaskablePixmapWidget()
{
delete renderTarget;
}
void MaskablePixmapWidget::autopickBackground() void MaskablePixmapWidget::autopickBackground()
{ {
QImage pic = pixmap.toImage(); QImage pic = pixmap.toImage();

View File

@ -24,7 +24,7 @@ class MaskablePixmapWidget : public QWidget
Q_OBJECT Q_OBJECT
public: public:
MaskablePixmapWidget(QWidget *parent, QSize size, QString maskName = QString()); MaskablePixmapWidget(QWidget *parent, QSize size, QString maskName = QString());
~MaskablePixmapWidget();
void autopickBackground(); void autopickBackground();
void setClickable(bool clickable); void setClickable(bool clickable);
void setPixmap(const QPixmap &pmap, QColor background); void setPixmap(const QPixmap &pmap, QColor background);

View File

@ -34,8 +34,8 @@ ScreenshotGrabber::ScreenshotGrabber(QWidget* parent)
: QWidget(parent) : QWidget(parent)
{ {
QGraphicsScene* scene = new QGraphicsScene; scene = new QGraphicsScene;
this->window = new QGraphicsView (scene); // Top-level widget window = new QGraphicsView (scene); // Top-level widget
setupWindow(); setupWindow();
setupScene(scene); setupScene(scene);
@ -45,6 +45,7 @@ ScreenshotGrabber::ScreenshotGrabber(QWidget* parent)
ScreenshotGrabber::~ScreenshotGrabber() ScreenshotGrabber::~ScreenshotGrabber()
{ {
delete scene;
} }
bool ScreenshotGrabber::eventFilter(QObject* object, QEvent* event) bool ScreenshotGrabber::eventFilter(QObject* object, QEvent* event)

View File

@ -71,13 +71,13 @@ private:
void beginRectChooser(QGraphicsSceneMouseEvent* event); void beginRectChooser(QGraphicsSceneMouseEvent* event);
QPixmap screenGrab; QPixmap screenGrab;
QGraphicsScene* scene;
QGraphicsView* window; QGraphicsView* window;
QGraphicsPixmapItem* screenGrabDisplay; QGraphicsPixmapItem* screenGrabDisplay;
ScreenGrabberOverlayItem* overlay; ScreenGrabberOverlayItem* overlay;
ScreenGrabberChooserRectItem* chooserRect; ScreenGrabberChooserRectItem* chooserRect;
ToolBoxGraphicsItem* helperToolbox; ToolBoxGraphicsItem* helperToolbox;
QGraphicsTextItem* helperTooltip; QGraphicsTextItem* helperTooltip;
}; };