diff --git a/src/core/core.cpp b/src/core/core.cpp index a377190ec..2dd743987 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -1248,7 +1248,7 @@ QString Core::getFriendUsername(uint32_t friendnumber) const uint8_t* name = new uint8_t[namesize]; tox_friend_get_name(tox, friendnumber, name, nullptr); QString sname = CString::toString(name, namesize); - delete name; + delete[] name; return sname; } diff --git a/src/misc/qrwidget.cpp b/src/misc/qrwidget.cpp index 52069124c..3493c5765 100644 --- a/src/misc/qrwidget.cpp +++ b/src/misc/qrwidget.cpp @@ -21,6 +21,11 @@ QRWidget::QRWidget(QWidget *parent) : QWidget(parent), data("0") image = new QImage(size, QImage::Format_RGB32); } +QRWidget::~QRWidget() +{ + delete image; +} + void QRWidget::setQRData(const QString& data) { this->data = data; diff --git a/src/misc/qrwidget.h b/src/misc/qrwidget.h index cc66f4e97..59bfc479b 100644 --- a/src/misc/qrwidget.h +++ b/src/misc/qrwidget.h @@ -11,6 +11,7 @@ class QRWidget : public QWidget public: explicit QRWidget(QWidget *parent = 0); + ~QRWidget(); void setQRData(const QString& data); QImage* getImage(); bool saveImage(QString path); diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index fcce94312..4ac15f849 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -69,7 +69,7 @@ ChatForm::ChatForm(Friend* chatFriend) typingTimer.setSingleShot(true); - netcam = new NetCamView(); + netcam = nullptr; callDurationTimer = nullptr; disableCallButtonsTimer = nullptr; @@ -307,7 +307,7 @@ void ChatForm::onAvStart(uint32_t FriendId, int CallId, bool video) connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered())); - netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getDisplayedName()); + showNetcam(); } else { @@ -349,7 +349,7 @@ void ChatForm::onAvCancel(uint32_t FriendId, int) enableCallButtons(); stopCounter(); - netcam->hide(); + hideNetcam(); addSystemInfoMessage(tr("%1 stopped calling").arg(f->getDisplayedName()), ChatMessage::INFO, QDateTime::currentDateTime()); } @@ -366,7 +366,7 @@ void ChatForm::onAvEnd(uint32_t FriendId, int) enableCallButtons(); stopCounter(); - netcam->hide(); + hideNetcam(); } 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")); connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered())); - netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getDisplayedName()); + showNetcam(); } else { @@ -453,7 +453,7 @@ void ChatForm::onAvEnding(uint32_t FriendId, int) enableCallButtons(); stopCounter(); - netcam->hide(); + hideNetcam(); } void ChatForm::onAvRequestTimeout(uint32_t FriendId, int) @@ -469,7 +469,7 @@ void ChatForm::onAvRequestTimeout(uint32_t FriendId, int) enableCallButtons(); stopCounter(); - netcam->hide(); + hideNetcam(); } void ChatForm::onAvPeerTimeout(uint32_t FriendId, int) @@ -485,7 +485,7 @@ void ChatForm::onAvPeerTimeout(uint32_t FriendId, int) enableCallButtons(); stopCounter(); - netcam->hide(); + hideNetcam(); } 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())); - netcam->hide(); + hideNetcam(); } 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"; if (video) - netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getDisplayedName()); + showNetcam(); else - netcam->hide(); + hideNetcam(); } void ChatForm::onAnswerCallTriggered() @@ -538,7 +538,7 @@ void ChatForm::onHangupCallTriggered() qDebug() << "onHangupCallTriggered"; //Fixes an OS X bug with ending a call while in full screen - if (netcam->isFullScreen()) + if (netcam && netcam->isFullScreen()) netcam->showNormal(); audioInputFlag = false; @@ -606,7 +606,7 @@ void ChatForm::onCancelCallTriggered() enableCallButtons(); - netcam->hide(); + hideNetcam(); emit cancelCall(callId, f->getFriendID()); } @@ -1035,3 +1035,19 @@ void ChatForm::SendMessageStr(QString msg) 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; +} diff --git a/src/widget/form/chatform.h b/src/widget/form/chatform.h index 28a703b2d..ad4355a2a 100644 --- a/src/widget/form/chatform.h +++ b/src/widget/form/chatform.h @@ -99,6 +99,8 @@ private slots: void doScreenshot(); protected: + void showNetcam(); + void hideNetcam(); // drag & drop void dragEnterEvent(QDragEnterEvent* ev); void dropEvent(QDropEvent* ev); diff --git a/src/widget/form/profileform.cpp b/src/widget/form/profileform.cpp index 66561035d..743172eb4 100644 --- a/src/widget/form/profileform.cpp +++ b/src/widget/form/profileform.cpp @@ -49,7 +49,7 @@ void ProfileForm::refreshProfiles() } ProfileForm::ProfileForm(QWidget *parent) : - QWidget(parent) + QWidget{parent}, qr{nullptr} { bodyUI = new Ui::IdentitySettings; bodyUI->setupUi(this); @@ -132,6 +132,7 @@ ProfileForm::ProfileForm(QWidget *parent) : ProfileForm::~ProfileForm() { + delete qr; delete bodyUI; head->deleteLater(); } @@ -182,6 +183,7 @@ void ProfileForm::setToxId(const QString& id) toxId->setText(id); toxId->setCursorPosition(0); + delete qr; qr = new QRWidget(); qr->setQRData("tox:"+id); bodyUI->qrCode->setPixmap(QPixmap::fromImage(qr->getImage()->scaledToWidth(150))); diff --git a/src/widget/maskablepixmapwidget.cpp b/src/widget/maskablepixmapwidget.cpp index acd975dfd..8ac5719f5 100644 --- a/src/widget/maskablepixmapwidget.cpp +++ b/src/widget/maskablepixmapwidget.cpp @@ -26,6 +26,11 @@ MaskablePixmapWidget::MaskablePixmapWidget(QWidget *parent, QSize size, QString setSize(size); } +MaskablePixmapWidget::~MaskablePixmapWidget() +{ + delete renderTarget; +} + void MaskablePixmapWidget::autopickBackground() { QImage pic = pixmap.toImage(); diff --git a/src/widget/maskablepixmapwidget.h b/src/widget/maskablepixmapwidget.h index 15104f9bb..8e4df1a4e 100644 --- a/src/widget/maskablepixmapwidget.h +++ b/src/widget/maskablepixmapwidget.h @@ -24,7 +24,7 @@ class MaskablePixmapWidget : public QWidget Q_OBJECT public: MaskablePixmapWidget(QWidget *parent, QSize size, QString maskName = QString()); - + ~MaskablePixmapWidget(); void autopickBackground(); void setClickable(bool clickable); void setPixmap(const QPixmap &pmap, QColor background); diff --git a/src/widget/tool/screenshotgrabber.cpp b/src/widget/tool/screenshotgrabber.cpp index be1108573..4576cefdc 100644 --- a/src/widget/tool/screenshotgrabber.cpp +++ b/src/widget/tool/screenshotgrabber.cpp @@ -34,8 +34,8 @@ ScreenshotGrabber::ScreenshotGrabber(QWidget* parent) : QWidget(parent) { - QGraphicsScene* scene = new QGraphicsScene; - this->window = new QGraphicsView (scene); // Top-level widget + scene = new QGraphicsScene; + window = new QGraphicsView (scene); // Top-level widget setupWindow(); setupScene(scene); @@ -45,6 +45,7 @@ ScreenshotGrabber::ScreenshotGrabber(QWidget* parent) ScreenshotGrabber::~ScreenshotGrabber() { + delete scene; } bool ScreenshotGrabber::eventFilter(QObject* object, QEvent* event) diff --git a/src/widget/tool/screenshotgrabber.h b/src/widget/tool/screenshotgrabber.h index ad0fce9f7..94d22a845 100644 --- a/src/widget/tool/screenshotgrabber.h +++ b/src/widget/tool/screenshotgrabber.h @@ -71,13 +71,13 @@ private: void beginRectChooser(QGraphicsSceneMouseEvent* event); QPixmap screenGrab; + QGraphicsScene* scene; QGraphicsView* window; QGraphicsPixmapItem* screenGrabDisplay; ScreenGrabberOverlayItem* overlay; ScreenGrabberChooserRectItem* chooserRect; ToolBoxGraphicsItem* helperToolbox; QGraphicsTextItem* helperTooltip; - };