Merge lp:~aacid/thumbnailer/fix_factory_leak into lp:thumbnailer/devel

Proposed by Albert Astals Cid
Status: Merged
Approved by: Michi Henning
Approved revision: 255
Merged at revision: 254
Proposed branch: lp:~aacid/thumbnailer/fix_factory_leak
Merge into: lp:thumbnailer/devel
Diff against target: 84 lines (+10/-17)
2 files modified
plugins/Ubuntu/Thumbnailer.0.1/thumbnailerimageresponse.cpp (+9/-14)
plugins/Ubuntu/Thumbnailer.0.1/thumbnailerimageresponse.h (+1/-3)
To merge this branch: bzr merge lp:~aacid/thumbnailer/fix_factory_leak
Reviewer Review Type Date Requested Status
Michi Henning (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+268081@code.launchpad.net

Commit message

Only create the QQuickTextureFactory when needed

Fixes leak when the response is cancelled

Description of the change

Only create the QQuickTextureFactory when needed

To post a comment you must log in.
Revision history for this message
Albert Astals Cid (aacid) wrote :

A question i just realized. Why are you guys calling finished() from the constructor?

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Michi Henning (michihenning) wrote :

Needs a trivial fix on line 90 of thumbnailerimageresponse.cpp to compile. (Missing internal namespace qualifier.) Otherwise, looks good to me!

review: Needs Fixing
Revision history for this message
James Henstridge (jamesh) wrote :

Albert: we are calling finished from the constructor when we know we've hit an error condition. The signal emission is delayed via invokeMethod() to give the caller an opportunity to connect to the signal.

255. By Albert Astals Cid

compile++

Revision history for this message
Albert Astals Cid (aacid) wrote :

> Needs a trivial fix on line 90 of thumbnailerimageresponse.cpp to compile.
> (Missing internal namespace qualifier.) Otherwise, looks good to me!

Done.

Revision history for this message
Albert Astals Cid (aacid) wrote :

> Albert: we are calling finished from the constructor when we know we've hit an
> error condition. The signal emission is delayed via invokeMethod() to give
> the caller an opportunity to connect to the signal.

Ah, ThumbnailerImageResponse::ThumbnailerImageResponse(QSize const& requested_size, QString const& default_image) always gives out the default image, ok.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michi Henning (michihenning) wrote :

Cool, thank you!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/Ubuntu/Thumbnailer.0.1/thumbnailerimageresponse.cpp'
2--- plugins/Ubuntu/Thumbnailer.0.1/thumbnailerimageresponse.cpp 2015-07-29 18:24:18 +0000
3+++ plugins/Ubuntu/Thumbnailer.0.1/thumbnailerimageresponse.cpp 2015-08-17 08:29:34 +0000
4@@ -47,7 +47,6 @@
5 : requested_size_(requested_size)
6 , default_image_(default_image)
7 {
8- loadDefaultImage();
9 // Queue the signal emission so there is time for the caller to connect.
10 QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection);
11 }
12@@ -56,7 +55,14 @@
13
14 QQuickTextureFactory* ThumbnailerImageResponse::textureFactory() const
15 {
16- return texture_;
17+ if (!image_.isNull()) {
18+ return QQuickTextureFactory::textureFactoryForImage(image_);
19+ } else {
20+ char const* env_default = getenv("THUMBNAILER_TEST_DEFAULT_IMAGE");
21+ QImage aux;
22+ aux.load(env_default ? QString(env_default) : default_image_);
23+ return QQuickTextureFactory::textureFactoryForImage(aux);
24+ }
25 }
26
27 void ThumbnailerImageResponse::cancel()
28@@ -68,21 +74,12 @@
29 watcher_.reset();
30 }
31
32-void ThumbnailerImageResponse::loadDefaultImage()
33-{
34- char const* env_default = getenv("THUMBNAILER_TEST_DEFAULT_IMAGE");
35- QImage result;
36- result.load(env_default ? QString(env_default) : default_image_);
37- texture_ = QQuickTextureFactory::textureFactoryForImage(result);
38-}
39-
40 void ThumbnailerImageResponse::dbusCallFinished()
41 {
42 QDBusPendingReply<QDBusUnixFileDescriptor> reply = *watcher_.get();
43 if (!reply.isValid())
44 {
45 qWarning() << "ThumbnailerImageResponse::dbusCallFinished(): D-Bus error: " << reply.error().message();
46- loadDefaultImage();
47 Q_EMIT finished();
48 return;
49 }
50@@ -90,8 +87,7 @@
51 try
52 {
53 QSize realSize;
54- QImage image = internal::imageFromFd(reply.value().fileDescriptor(), &realSize, requested_size_);
55- texture_ = QQuickTextureFactory::textureFactoryForImage(image);
56+ image_ = internal::imageFromFd(reply.value().fileDescriptor(), &realSize, requested_size_);
57 Q_EMIT finished();
58 return;
59 }
60@@ -105,7 +101,6 @@
61 qWarning() << "ThumbnailerImageResponse::dbusCallFinished(): unknown exception";
62 }
63
64- loadDefaultImage();
65 Q_EMIT finished();
66 // LCOV_EXCL_STOP
67 }
68
69=== modified file 'plugins/Ubuntu/Thumbnailer.0.1/thumbnailerimageresponse.h'
70--- plugins/Ubuntu/Thumbnailer.0.1/thumbnailerimageresponse.h 2015-06-12 23:52:13 +0000
71+++ plugins/Ubuntu/Thumbnailer.0.1/thumbnailerimageresponse.h 2015-08-17 08:29:34 +0000
72@@ -52,11 +52,9 @@
73 void dbusCallFinished();
74
75 private:
76- void loadDefaultImage();
77-
78 QString id_;
79 QSize requested_size_;
80- QQuickTextureFactory * texture_ = nullptr;
81+ QImage image_;
82 QString default_image_;
83 std::unique_ptr<QDBusPendingCallWatcher> watcher_;
84 };

Subscribers

People subscribed via source and target branches

to all changes: