Skip to content

Commit c82a45d

Browse files
committed
fix: avoid memory leak
as title Log: as title Pms: BUG-318023
1 parent 8073385 commit c82a45d

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/dde-session/main.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,19 @@ int main(int argc, char *argv[])
9393
org::freedesktop::systemd1::Manager systemdDBus("org.freedesktop.systemd1", "/org/freedesktop/systemd1", QDBusConnection::sessionBus());
9494
startSystemdUnit(systemdDBus, dmService, "replace");
9595

96-
QDBusServiceWatcher *watcher = new QDBusServiceWatcher("org.deepin.dde.Session1", QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForUnregistration);
96+
QDBusServiceWatcher *watcher = new QDBusServiceWatcher("org.deepin.dde.Session1", QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForUnregistration, &app);
9797
watcher->connect(watcher, &QDBusServiceWatcher::serviceUnregistered, [&] {
9898
qInfo() << "dde session exit";
9999
startSystemdUnit(systemdDBus, "dde-session-exit-task.service", "replace");
100100
qApp->quit();
101101
});
102-
pid_t curPid = getpid();
103-
QThreadPool::globalInstance()->start([curPid]() {
104-
qInfo()<<"leader pipe thread id: " << QThread::currentThreadId() << ", pid: " << curPid;
105-
Fifo *fifo = new Fifo;
102+
103+
{ // none block
104+
pid_t curPid = getpid();
105+
Fifo *fifo = new Fifo(&app);
106106
fifo->OpenWrite();
107107
fifo->Write(QString::number(curPid));
108-
});
109-
108+
}
110109
// We started the unit, open <dbus> and sleep forever.
111110
return app.exec();
112111
}
@@ -116,7 +115,7 @@ int main(int argc, char *argv[])
116115
// QProcess no block "/usr/bin/deepin-keyring-whitebox", "--opt-client=waitfifonotify"),BUG-255907
117116
QProcess::startDetached("/usr/bin/deepin-keyring-whitebox", QStringList() << "--opt-client=waitfifonotify");
118117

119-
auto* session = new Session;
118+
auto* session = new Session(&app);
120119
new Session1Adaptor(session);
121120
QDBusConnection::sessionBus().registerService("org.deepin.dde.Session1");
122121
QDBusConnection::sessionBus().registerObject("/org/deepin/dde/Session1", "org.deepin.dde.Session1", session);
@@ -126,7 +125,7 @@ int main(int argc, char *argv[])
126125
QDBusConnection::sessionBus().registerService("org.deepin.dde.SessionManager1");
127126
QDBusConnection::sessionBus().registerObject("/org/deepin/dde/SessionManager1", "org.deepin.dde.SessionManager1", SessionManager::instance());
128127

129-
auto *wmSwitcher = new WMSwitcher();
128+
auto *wmSwitcher = new WMSwitcher(&app);
130129
new WMSwitcher1Adaptor(wmSwitcher);
131130
QDBusConnection::sessionBus().registerService("org.deepin.dde.WMSwitcher1");
132131
QDBusConnection::sessionBus().registerObject("/org/deepin/dde/WMSwitcher1", wmSwitcher);
@@ -151,7 +150,7 @@ int main(int argc, char *argv[])
151150

152151
QThreadPool::globalInstance()->start([&session]() {
153152
qInfo()<< "systemd service pipe thread id: " << QThread::currentThreadId();
154-
Fifo *fifo = new Fifo;
153+
Fifo *fifo = new Fifo();
155154
fifo->OpenRead();
156155
qInfo() << "pipe open read finish";
157156
QString CurSessionPid;
@@ -166,6 +165,7 @@ int main(int argc, char *argv[])
166165
session->setSessionPath();
167166
}
168167
}
168+
fifo->deleteLater();
169169
qInfo() << "pipe read finish, app exit.";
170170
qApp->quit();
171171
});

src/utils/fifo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
#include <errno.h>
1414
#include <QDebug>
1515

16-
Fifo::Fifo()
17-
: m_fd(-1)
16+
Fifo::Fifo(QObject *parent)
17+
: QObject(parent)
18+
, m_fd(-1)
1819
{
1920
m_fifoPath = QString(getenv("HOME")) + "/.cache/dde-session-fifo";
2021
}

src/utils/fifo.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010

1111
class Fifo : public QObject
1212
{
13+
Q_OBJECT
1314
public:
14-
Fifo();
15-
~Fifo();
15+
Fifo(QObject *parent = nullptr);
16+
virtual ~Fifo();
1617

1718
int Read(QString &data);
1819
int Write(QString data);

0 commit comments

Comments
 (0)