Fix - memory leaks

This commit is contained in:
Yuriy Puchkov
2020-10-15 13:06:38 +03:00
parent 2245c4709a
commit 9eb1a7cb18
6 changed files with 32 additions and 11 deletions

View File

@@ -10,7 +10,6 @@
#include <QDesktopServices>
#include <QDesktopWidget>
#include <QFileInfo>
#include <QHBoxLayout>
#include <QIcon>
#include <QLabel>
#include <QLayoutItem>
@@ -46,6 +45,11 @@ HistoryWidget::HistoryWidget(QWidget* parent)
loadHistory();
}
HistoryWidget::~HistoryWidget()
{
delete m_notification;
}
void HistoryWidget::loadHistory()
{
// read history files
@@ -140,9 +144,7 @@ void HistoryWidget::addLine(const QString& path, const QString& fileName)
// TODO - remove dependency injection (s3 & imgur)
if (unpackFileName.type.compare(SCREENSHOT_STORAGE_TYPE_S3) == 0) {
if (unpackFileName.token.length() > 0) {
ImgS3Uploader* uploader = new ImgS3Uploader();
removeItem(
uploader, phbl, unpackFileName.file, unpackFileName.token);
removeItem(phbl, unpackFileName.file, unpackFileName.token);
} else {
// for compatibility with previous versions and to be able to
// remove previous screenshots
@@ -176,18 +178,19 @@ void HistoryWidget::addLine(const QString& path, const QString& fileName)
m_pVBox->addLayout(phbl);
}
void HistoryWidget::removeItem(ImgUploader* imgUploader,
QLayout* pl,
void HistoryWidget::removeItem(QLayout* pl,
const QString& fileName,
const QString& deleteToken)
{
hide();
ImgS3Uploader* imgUploader = new ImgS3Uploader();
imgUploader->show();
imgUploader->deleteResource(fileName, deleteToken);
connect(imgUploader, &QWidget::destroyed, this, [=]() {
if (imgUploader->resultStatus) {
removeLayoutItem(pl);
}
imgUploader->deleteLater();
show();
});
}