Merge lp:~michihenning/online-accounts-api/leak-fix into lp:online-accounts-api

Proposed by Michi Henning
Status: Merged
Approved by: Alberto Mardegan
Approved revision: 44
Merged at revision: 42
Proposed branch: lp:~michihenning/online-accounts-api/leak-fix
Merge into: lp:online-accounts-api
Diff against target: 42 lines (+4/-2)
3 files modified
src/lib/OnlineAccounts/pending_call.h (+2/-1)
src/lib/OnlineAccountsDaemon/i18n.cpp (+1/-1)
src/lib/Ubuntu/OnlineAccounts.2/account.cpp (+1/-0)
To merge this branch: bzr merge lp:~michihenning/online-accounts-api/leak-fix
Reviewer Review Type Date Requested Status
Alberto Mardegan (community) Approve
Review via email: mp+313667@code.launchpad.net

Commit message

Fixed memory leak in PendingCallWatcher.
Got rid of compiler warning.
Added missing \endlist to documentation.

Description of the change

Fixed memory leak in PendingCallWatcher.
Got rid of compiler warning.
Added missing \endlist to documentation.

This would not have happened with std::unique_ptr or QScopedPointer. I strongly recommend to never use raw pointers. As this particular example demonstrates, it is easy to get even the most simple case wrong. It took me considerable time to track this down; much better to not allow this type of error to ever arise in the first place.

To post a comment you must log in.
Revision history for this message
Alberto Mardegan (mardy) wrote :

Hi Michi! I still do prefer an explicit delete, when the lifetime of the object is as simple as in this case (and yet I forgot it! :-) ).
If you still decide to go for the QScopedPointer, please add its include file to pending_call.h (now it works even without it, but compilation might break on a future Qt release).

review: Needs Fixing
44. By Michi Henning

Added include for QScopedPointer.

Revision history for this message
Michi Henning (michihenning) wrote :

Well, if this doesn't convince you, I don't know what will. This has cost us quite a few hours. And, by using QScopedPointer or unique_ptr, this bug could never have happened in the first place.

I cannot for the life of me see what writing the code with a raw pointer and an explicit delete is preferable when, with a smart pointer, no code is needed at all.

Revision history for this message
Alberto Mardegan (mardy) wrote :

It's just that old habits are hard to die, but hey, I'm trying to change :-)

review: Approve
Revision history for this message
Michi Henning (michihenning) wrote :
Revision history for this message
Michi Henning (michihenning) wrote :

Mardy, I don't know the correct process for this project. I take it that you will merge and release this?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/lib/OnlineAccounts/pending_call.h'
--- src/lib/OnlineAccounts/pending_call.h 2015-02-27 10:28:50 +0000
+++ src/lib/OnlineAccounts/pending_call.h 2016-12-21 07:21:59 +0000
@@ -23,6 +23,7 @@
2323
24#include <QExplicitlySharedDataPointer>24#include <QExplicitlySharedDataPointer>
25#include <QObject>25#include <QObject>
26#include <QScopedPointer>
2627
27#include "global.h"28#include "global.h"
2829
@@ -69,7 +70,7 @@
6970
70private:71private:
71 Q_DECLARE_PRIVATE(PendingCallWatcher)72 Q_DECLARE_PRIVATE(PendingCallWatcher)
72 PendingCallWatcherPrivate *d_ptr;73 QScopedPointer<PendingCallWatcherPrivate> d_ptr;
73};74};
7475
75} // namespace76} // namespace
7677
=== modified file 'src/lib/OnlineAccountsDaemon/i18n.cpp'
--- src/lib/OnlineAccountsDaemon/i18n.cpp 2016-11-07 08:01:24 +0000
+++ src/lib/OnlineAccountsDaemon/i18n.cpp 2016-12-21 07:21:59 +0000
@@ -31,4 +31,4 @@
31 text.toUtf8().constData()));31 text.toUtf8().constData()));
32}32}
3333
34}; // namespace34} // namespace
3535
=== modified file 'src/lib/Ubuntu/OnlineAccounts.2/account.cpp'
--- src/lib/Ubuntu/OnlineAccounts.2/account.cpp 2016-11-07 13:19:06 +0000
+++ src/lib/Ubuntu/OnlineAccounts.2/account.cpp 2016-12-21 07:21:59 +0000
@@ -205,6 +205,7 @@
205 * \li \c displayName - the localized display name for the service205 * \li \c displayName - the localized display name for the service
206 * \li \c iconSource - URL for the icon; can be a "file://" URL to a local206 * \li \c iconSource - URL for the icon; can be a "file://" URL to a local
207 * file, or an icon from the theme if the URL starts with "image://theme/"207 * file, or an icon from the theme if the URL starts with "image://theme/"
208 * \endlist
208 */209 */
209QJSValue Account::service() const210QJSValue Account::service() const
210{211{

Subscribers

People subscribed via source and target branches

to all changes: