Skip to content

Commit

Permalink
Fix some memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammetasan committed Nov 9, 2019
1 parent 2d05079 commit 3e1a12d
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 23 deletions.
8 changes: 7 additions & 1 deletion stacer-core/Info/disk_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ QList<Disk*> DiskInfo::getDisks() const

void DiskInfo::updateDiskInfo()
{
qDeleteAll(disks);
disks.clear();

QList<QStorageInfo> storageInfoList = QStorageInfo::mountedVolumes();

for(const QStorageInfo &info: storageInfoList) {
if (info.isValid()) {
Disk *disk = new Disk;
Disk *disk = new Disk();
disk->name = info.displayName();
disk->device = info.device();
disk->size = info.bytesTotal();
Expand All @@ -37,6 +38,11 @@ QList<QString> DiskInfo::devices()
return set.toList();
}

DiskInfo::~DiskInfo()
{
qDeleteAll(disks);
}

QList<QString> DiskInfo::fileSystemTypes()
{
QSet<QString> set;
Expand Down
4 changes: 2 additions & 2 deletions stacer-core/Info/disk_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class STACERCORESHARED_EXPORT DiskInfo
QString getDiskName() const;
QList<QString> fileSystemTypes();
QList<QString> devices();
~DiskInfo();

private:
QList<Disk*> disks;
};

class Disk {
public:
struct Disk {
QString name;
QString device;
QString fileSystemType;
Expand Down
7 changes: 3 additions & 4 deletions stacer-core/Tools/service_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ QList<Service> ServiceTool::getServicesWithSystemctl()
.filter(QRegExp("[^@].service"));

QRegExp sep("\\s+");
for (const QString line : lines)
services.reserve(lines.size());
for (const QString &line : lines)
{
// e.g apache2.service [enabled|disabled]
QStringList s = line.trimmed().split(sep);
Expand All @@ -32,9 +33,7 @@ QList<Service> ServiceTool::getServicesWithSystemctl()
bool status = ! s.last().trimmed().compare("enabled");
bool active = serviceIsActive(s.first().trimmed());

Service service(name, description, status, active);

services << service;
services.push_back({name, description, status, active});
}

} catch(QString &ex) {
Expand Down
4 changes: 3 additions & 1 deletion stacer-core/Utils/command_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <QStandardPaths>
#include <QDebug>

#include <memory>

QString CommandUtil::sudoExec(const QString &cmd, QStringList args, QByteArray data)
{
args.push_front(cmd);
Expand All @@ -22,7 +24,7 @@ QString CommandUtil::sudoExec(const QString &cmd, QStringList args, QByteArray d

QString CommandUtil::exec(const QString &cmd, QStringList args, QByteArray data)
{
QProcess* process = new QProcess;
std::unique_ptr<QProcess> process(new QProcess());
process->start(cmd, args);

if (! data.isEmpty()) {
Expand Down
7 changes: 4 additions & 3 deletions stacer/Pages/Dashboard/dashboard_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void DashboardPage::init()
connect(mTimer, &QTimer::timeout, this, &DashboardPage::updateMemoryBar);
connect(mTimer, &QTimer::timeout, this, &DashboardPage::updateNetworkBar);

QTimer *timerDisk = new QTimer;
QTimer *timerDisk = new QTimer(this);
connect(timerDisk, &QTimer::timeout, this, &DashboardPage::updateDiskBar);
timerDisk->start(5 * 1000);

Expand Down Expand Up @@ -116,8 +116,9 @@ void DashboardPage::systemInformationInit()
<< tr("CPU Core: %1").arg(sysInfo.getCpuCore())
<< tr("CPU Speed: %1").arg(sysInfo.getCpuSpeed());

QStringListModel *systemInfoModel = new QStringListModel(infos);

QStringListModel *systemInfoModel = new QStringListModel(infos,ui->listViewSystemInfo);
const auto oldModel = ui->listViewSystemInfo->selectionModel();
delete oldModel;
ui->listViewSystemInfo->setModel(systemInfoModel);
}

Expand Down
4 changes: 2 additions & 2 deletions stacer/Pages/Helpers/host_manage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ void HostManage::on_btnNewHost_clicked()

void HostManage::loadTableRowMenu()
{
QAction *actionOpenFolder = new QAction(QIcon(":/static/themes/common/img/folder.png"), tr("Edit"));
QAction *actionOpenFolder = new QAction(QIcon(":/static/themes/common/img/folder.png"), tr("Edit"),&mTableRowMenu);
actionOpenFolder->setData("edit");
mTableRowMenu.addAction(actionOpenFolder);

QAction *actionDelete = new QAction(QIcon(":/static/themes/common/img/delete.png"), tr("Delete"));
QAction *actionDelete = new QAction(QIcon(":/static/themes/common/img/delete.png"), tr("Delete"),&mTableRowMenu);
actionDelete->setData("delete");
mTableRowMenu.addAction(actionDelete);
}
Expand Down
8 changes: 5 additions & 3 deletions stacer/Pages/Processes/processes_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,17 @@ void ProcessesPage::init()
void ProcessesPage::loadHeaderMenu()
{
int i = 0;
QList<QAction*> actionList;
actionList.reserve(mHeaders.size());
for (const QString &header : mHeaders) {
QAction *action = new QAction(header);
QAction *action = new QAction(header,&mHeaderMenu);
action->setCheckable(true);
action->setChecked(true);
action->setData(i++);
actionList.push_back(action);

mHeaderMenu.addAction(action);
}

mHeaderMenu.addActions(actionList);
// exclude headers
QList<int> hiddenHeaders = { 3, 6, 7, 8, 9, 10, 11 };

Expand Down
10 changes: 6 additions & 4 deletions stacer/Pages/Search/search_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,17 @@ void SearchPage::loadTableRowMenu()
void SearchPage::loadHeaderMenu()
{
int i = 0;
QList<QAction*> actionList;
actionList.reserve(mTableHeaders.size());

for (const QString &header : mTableHeaders) {
QAction *action = new QAction(header);
QAction *action = new QAction(header,&mHeaderMenu);
action->setCheckable(true);
action->setChecked(true);
action->setData(i++);

mHeaderMenu.addAction(action);
actionList.push_back(action);
}

mHeaderMenu.addActions(actionList);
// exclude headers
QList<int> hiddenHeaders = { 4, 6, 7, 8 };

Expand Down
4 changes: 2 additions & 2 deletions stacer/Pages/SystemCleaner/system_cleaner_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ void SystemCleanerPage::init()
connect(SignalMapper::ins(), &SignalMapper::sigChangedAppTheme, [=] {
QString themeName = SettingManager::ins()->getThemeName();

mLoadingMovie = new QMovie(QString(":/static/themes/%1/img/scanLoading.gif").arg(themeName));
mLoadingMovie = new QMovie(QString(":/static/themes/%1/img/scanLoading.gif").arg(themeName),{},this);
ui->lblLoadingScanner->setMovie(mLoadingMovie);
mLoadingMovie->start();
ui->lblLoadingScanner->hide();

mLoadingMovie_2 = new QMovie(QString(":/static/themes/%1/img/loading.gif").arg(themeName));
mLoadingMovie_2 = new QMovie(QString(":/static/themes/%1/img/loading.gif").arg(themeName),{},this);
ui->lblLoadingCleaner->setMovie(mLoadingMovie_2);
mLoadingMovie_2->start();
ui->lblLoadingCleaner->hide();
Expand Down
2 changes: 1 addition & 1 deletion stacer/Pages/SystemCleaner/system_cleaner_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SystemCleanerPage : public QWidget
};

public:
explicit SystemCleanerPage(QWidget *parent = 0);
explicit SystemCleanerPage(QWidget *parent = nullptr);
~SystemCleanerPage();

private slots:
Expand Down

0 comments on commit 3e1a12d

Please sign in to comment.