diff options
author | Rachel Powers <508861+Ryex@users.noreply.github.com> | 2023-07-05 21:18:49 -0700 |
---|---|---|
committer | Rachel Powers <508861+Ryex@users.noreply.github.com> | 2023-07-05 21:18:49 -0700 |
commit | 71e73bb6f8c4a695e39f0c0fec901d8a5e5121b3 (patch) | |
tree | b5bc108a75add97b3e6b91150087cd2079d792ff | |
parent | 8638076aa1cf3f1a975ac59ddaf0286acc7d39e2 (diff) | |
download | PrismLauncher-71e73bb6f8c4a695e39f0c0fec901d8a5e5121b3.tar.gz PrismLauncher-71e73bb6f8c4a695e39f0c0fec901d8a5e5121b3.tar.bz2 PrismLauncher-71e73bb6f8c4a695e39f0c0fec901d8a5e5121b3.zip |
fix(tests): linux big task memory leak.
- move big_task into function scope
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
-rw-r--r-- | tests/Task_test.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/tests/Task_test.cpp b/tests/Task_test.cpp index 41e51f83..00d06794 100644 --- a/tests/Task_test.cpp +++ b/tests/Task_test.cpp @@ -50,31 +50,34 @@ class BigConcurrentTask : public ConcurrentTask { class BigConcurrentTaskThread : public QThread { Q_OBJECT - BigConcurrentTask big_task; void run() override { QTimer deadline; + BigConcurrentTask big_task; deadline.setInterval(10000); - connect(&deadline, &QTimer::timeout, this, [this] { passed_the_deadline = true; }); + bool* pt_deadline = &passed_the_deadline; + QMetaObject::Connection conn = connect(&deadline, &QTimer::timeout, this, [pt_deadline] { *pt_deadline = true; }); deadline.start(); // NOTE: Arbitrary value that manages to trigger a problem when there is one. // Considering each tasks, in a problematic state, adds 1024 * 4 bytes to the stack, // this number is enough to fill up 16 MiB of stack, more than enough to cause a problem. static const unsigned s_num_tasks = 1 << 12; - { - - for (unsigned i = 0; i < s_num_tasks; i++) { - auto sub_task = makeShared<BasicTask>(false); - big_task.addTask(sub_task); - } - - big_task.run(); - - while (!big_task.isFinished() && !passed_the_deadline) - QCoreApplication::processEvents(); - } // drop before emit + for (unsigned i = 0; i < s_num_tasks; i++) { + auto sub_task = makeShared<BasicTask>(false); + big_task.addTask(sub_task); + } + + big_task.run(); + + while (!big_task.isFinished() && !passed_the_deadline) + QCoreApplication::processEvents(); + // don't fire timer after this point + disconnect(conn); + if (deadline.isActive()) + deadline.stop(); + // task finished emit finished(); } |