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

Subscribers

People subscribed via source and target branches