Merge lp:~laney/ubuntu-system-settings/lp1375988 into lp:ubuntu-system-settings

Proposed by Iain Lane
Status: Merged
Approved by: Sebastien Bacher
Approved revision: 1104
Merged at revision: 1108
Proposed branch: lp:~laney/ubuntu-system-settings/lp1375988
Merge into: lp:ubuntu-system-settings
Diff against target: 116 lines (+20/-26)
1 file modified
plugins/about/storageabout.cpp (+20/-26)
To merge this branch: bzr merge lp:~laney/ubuntu-system-settings/lp1375988
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Sebastien Bacher (community) Approve
Review via email: mp+236934@code.launchpad.net

Commit message

[storage/about] Use a QSharedPointer to manage freeing of the counter which we use to display all of the collected sizes at once. If the measuring process was cancelled, we were freeing it multiple times - once for each outstanding size measurement. This led to a crash.

Description of the change

Use a QSharedPointer to properly manage the shared counter.

We were freeing it multiple times if the space measuring was cancelled.

To post a comment you must log in.
1104. By Iain Lane

Remove stray include for testing

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

Thanks, that seems to do the trick

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/about/storageabout.cpp'
2--- plugins/about/storageabout.cpp 2014-09-24 12:29:57 +0000
3+++ plugins/about/storageabout.cpp 2014-10-02 16:35:54 +0000
4@@ -43,18 +43,20 @@
5 }
6
7 struct MeasureData {
8- uint *running;
9+ QSharedPointer<quint32> running;
10 StorageAbout *object;
11 quint64 *size;
12 GCancellable *cancellable;
13- MeasureData (uint *running,
14+ MeasureData (QSharedPointer<quint32> running,
15 StorageAbout *object,
16 quint64 *size,
17 GCancellable *cancellable):
18 running(running),
19 object(object),
20 size(size),
21- cancellable(cancellable){}
22+ cancellable(cancellable){
23+ ++(*running);
24+ }
25 };
26
27 static void measure_file(const char * filename,
28@@ -84,19 +86,6 @@
29 measure_file (g_get_user_special_dir (directory), callback, user_data);
30 }
31
32-static void maybeEmit(MeasureData *data)
33-{
34- --(*data->running);
35-
36- if (*data->running == 0) {
37- Q_EMIT (data->object->sizeReady());
38- delete data->running;
39- }
40-
41- delete data;
42-
43-}
44-
45 static void measure_finished(GObject *source_object,
46 GAsyncResult *result,
47 gpointer user_data)
48@@ -118,20 +107,24 @@
49
50 if (err != nullptr) {
51 if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
52- delete data->running;
53 delete data;
54- g_object_unref (file);
55+ g_clear_object (&file);
56 g_error_free (err);
57+ err = nullptr;
58 return;
59 } else {
60 qWarning() << "Measuring of" << g_file_get_path (file)
61 << "failed:" << err->message;
62- g_error_free(err);
63+ g_error_free (err);
64+ err = nullptr;
65 }
66 }
67
68- g_object_unref (file);
69- maybeEmit(data);
70+ if (--(*data->running) == 0)
71+ Q_EMIT (data->object->sizeReady());
72+
73+ delete data;
74+ g_clear_object (&file);
75 }
76
77 StorageAbout::StorageAbout(QObject *parent) :
78@@ -310,7 +303,8 @@
79
80 void StorageAbout::populateSizes()
81 {
82- uint *running = new uint(0);
83+ quint32 *running = new quint32(0);
84+ QSharedPointer<quint32> running_ptr(running);
85
86 if (!m_cancellable)
87 m_cancellable = g_cancellable_new();
88@@ -318,25 +312,25 @@
89 measure_special_file(
90 G_USER_DIRECTORY_VIDEOS,
91 measure_finished,
92- new MeasureData(&++(*running), this, &m_moviesSize,
93+ new MeasureData(running_ptr, this, &m_moviesSize,
94 m_cancellable));
95
96 measure_special_file(
97 G_USER_DIRECTORY_MUSIC,
98 measure_finished,
99- new MeasureData(&++(*running), this, &m_audioSize,
100+ new MeasureData(running_ptr, this, &m_audioSize,
101 m_cancellable));
102
103 measure_special_file(
104 G_USER_DIRECTORY_PICTURES,
105 measure_finished,
106- new MeasureData(&++(*running), this, &m_picturesSize,
107+ new MeasureData(running_ptr, this, &m_picturesSize,
108 m_cancellable));
109
110 measure_file(
111 g_get_home_dir(),
112 measure_finished,
113- new MeasureData(&++(*running), this, &m_homeSize,
114+ new MeasureData(running_ptr, this, &m_homeSize,
115 m_cancellable));
116 }
117

Subscribers

People subscribed via source and target branches