Merge lp:~mandel/ubuntu-system-settings/mem-leak-fixes into lp:ubuntu-system-settings

Proposed by Manuel de la Peña
Status: Merged
Approved by: Sebastien Bacher
Approved revision: 1223
Merged at revision: 1231
Proposed branch: lp:~mandel/ubuntu-system-settings/mem-leak-fixes
Merge into: lp:ubuntu-system-settings
Diff against target: 154 lines (+52/-19)
3 files modified
debian/changelog (+6/-0)
plugins/system-update/download_tracker.cpp (+38/-13)
plugins/system-update/download_tracker.h (+8/-6)
To merge this branch: bzr merge lp:~mandel/ubuntu-system-settings/mem-leak-fixes
Reviewer Review Type Date Requested Status
Sebastien Bacher (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+243511@code.launchpad.net

Commit message

Fix mem leak in the update page.

Description of the change

The Download pointer returned by the download manager (as stated by the documentation) is owned by the caller and the memory should be managed by the client. This MR cleans the resource in the following cases:

* finished
* canceled
* error

There is also a small change that removes the definitions for a better cpp approach.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Sebastien Bacher (seb128) wrote :

Those change looks good, thanks (CI is failing due to issue with the infrastructure)

review: Approve
Revision history for this message
Sebastien Bacher (seb128) wrote :

recent changes look fine as well to me. Ken I read that you had issues testing the version before those changes, could you comment on what those were?

review: Approve
Revision history for this message
Manuel de la Peña (mandel) wrote :

I have tested this branch several times in vivid and everything works as expected. Would be nice to get kens feedback too :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2014-12-10 16:01:15 +0000
3+++ debian/changelog 2014-12-11 09:46:48 +0000
4@@ -38,6 +38,12 @@
5
6 -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Tue, 02 Dec 2014 19:39:55 +0000
7
8+ubuntu-system-settings (0.3+15.04.20141201-0ubuntu2) UNRELEASED; urgency=medium
9+
10+ * Fix mem leak in the update page.
11+
12+ -- Manuel de la Pena <manuel.delapena@canonical.com> Wed, 03 Dec 2014 11:11:00 +0100
13+
14 ubuntu-system-settings (0.3+15.04.20141201-0ubuntu1) vivid; urgency=low
15
16 [ Michał Sawicz ]
17
18=== modified file 'plugins/system-update/download_tracker.cpp'
19--- plugins/system-update/download_tracker.cpp 2014-09-30 02:05:36 +0000
20+++ plugins/system-update/download_tracker.cpp 2014-12-11 09:46:48 +0000
21@@ -18,22 +18,26 @@
22 * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
23 */
24
25+#include <QProcessEnvironment>
26+
27+#include <ubuntu/download_manager/download_struct.h>
28+#include <ubuntu/download_manager/error.h>
29+
30 #include "download_tracker.h"
31 #include "network/network.h"
32-#include <ubuntu/download_manager/download_struct.h>
33-#include <ubuntu/download_manager/error.h>
34-#include <QProcessEnvironment>
35
36-#define DOWNLOAD_COMMAND "post-download-command"
37-#define APP_ID "app_id"
38-#define PKCON_COMMAND "pkcon"
39+namespace {
40+ const QString DOWNLOAD_COMMAND = "post-download-command";
41+ const QString APP_ID = "app_id";
42+ const QString PKCON_COMMAND = "pkcon";
43+}
44
45 namespace UpdatePlugin {
46
47 DownloadTracker::DownloadTracker(QObject *parent) :
48 QObject(parent),
49- m_clickToken(""),
50- m_downloadUrl(""),
51+ m_clickToken(QString::null),
52+ m_downloadUrl(QString::null),
53 m_download(nullptr),
54 m_manager(nullptr),
55 m_progress(0)
56@@ -42,7 +46,7 @@
57
58 void DownloadTracker::setDownload(const QString& url)
59 {
60- if (url != "") {
61+ if (!url.isEmpty()) {
62 m_downloadUrl = url;
63 startService();
64 }
65@@ -50,7 +54,7 @@
66
67 void DownloadTracker::setClickToken(const QString& token)
68 {
69- if (token != "") {
70+ if (!token.isEmpty()) {
71 m_clickToken = token;
72 startService();
73 }
74@@ -58,7 +62,7 @@
75
76 void DownloadTracker::setPackageName(const QString& package)
77 {
78- if (package != "") {
79+ if (!package.isEmpty()) {
80 m_packageName = package;
81 startService();
82 }
83@@ -90,9 +94,9 @@
84 {
85 m_download = download;
86 connect(m_download, SIGNAL(finished(const QString &)), this,
87- SIGNAL(finished(const QString &)));
88+ SLOT(onDownloadFinished(const QString &)));
89 connect(m_download, SIGNAL(canceled(bool)), this,
90- SIGNAL(canceled(bool)));
91+ SLOT(onDownloadCanceled(bool)));
92 connect(m_download, SIGNAL(paused(bool)), this,
93 SIGNAL(paused(bool)));
94 connect(m_download, SIGNAL(resumed(bool)), this,
95@@ -112,6 +116,27 @@
96 void DownloadTracker::registerError(Error* error)
97 {
98 Q_EMIT errorFound(error->errorString());
99+
100+ // we need to ensure that the resources are cleaned
101+ m_download->deleteLater();
102+ m_download = nullptr;
103+}
104+
105+void DownloadTracker::onDownloadFinished(const QString& path)
106+{
107+ // once a download is finished we need to clean the resources
108+ m_download->deleteLater();
109+ m_download = nullptr;
110+ Q_EMIT finished(path);
111+}
112+
113+void DownloadTracker::onDownloadCanceled(bool wasCanceled)
114+{
115+ if (wasCanceled) {
116+ m_download->deleteLater();
117+ m_download = nullptr;
118+ }
119+ Q_EMIT canceled(wasCanceled);
120 }
121
122 void DownloadTracker::pause()
123
124=== modified file 'plugins/system-update/download_tracker.h'
125--- plugins/system-update/download_tracker.h 2014-09-30 02:05:36 +0000
126+++ plugins/system-update/download_tracker.h 2014-12-11 09:46:48 +0000
127@@ -63,6 +63,8 @@
128 void bindDownload(Download* download);
129 void setProgress(qulonglong received, qulonglong total);
130 void registerError(Ubuntu::DownloadManager::Error* error);
131+ void onDownloadFinished(const QString& path);
132+ void onDownloadCanceled(bool wasCanceled);
133
134 Q_SIGNALS:
135 void error(const QString &errorMessage);
136@@ -76,12 +78,12 @@
137 void errorFound(const QString &error);
138
139 private:
140- QString m_clickToken;
141- QString m_downloadUrl;
142- QString m_packageName;
143- Download* m_download;
144- Manager* m_manager;
145- int m_progress;
146+ QString m_clickToken = QString::null;
147+ QString m_downloadUrl = QString::null;
148+ QString m_packageName = QString::null;
149+ Download* m_download = nullptr;
150+ Manager* m_manager = nullptr;
151+ int m_progress = 0;
152
153 void startService();
154 QString getPkconCommand();

Subscribers

People subscribed via source and target branches