From 1b3ff96ffd3a249d2b4b278a4afc2714038560d7 Mon Sep 17 00:00:00 2001
From: Rachel Powers <508861+Ryex@users.noreply.github.com>
Date: Sun, 21 May 2023 01:46:28 -0700
Subject: fix: memory leak with NetJob and responce not getting cleaned up

Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
---
 launcher/tasks/ConcurrentTask.cpp | 27 +++++++++++----------------
 launcher/tasks/Task.cpp           |  2 +-
 launcher/tasks/Task.h             | 14 ++++++++++++++
 3 files changed, 26 insertions(+), 17 deletions(-)

(limited to 'launcher/tasks')

diff --git a/launcher/tasks/ConcurrentTask.cpp b/launcher/tasks/ConcurrentTask.cpp
index fae2f3dc..5ee14505 100644
--- a/launcher/tasks/ConcurrentTask.cpp
+++ b/launcher/tasks/ConcurrentTask.cpp
@@ -138,7 +138,7 @@ void ConcurrentTask::startNext()
     connect(next.get(), &Task::progress, this, [this, next](qint64 current, qint64 total) { subTaskProgress(next, current, total); });
 
     m_doing.insert(next.get(), next);
-    auto task_progress = std::make_shared<TaskStepProgress>(TaskStepProgress({ next->getUid() }));
+    auto task_progress = std::make_shared<TaskStepProgress>(next->getUid());
     m_task_progress.insert(next->getUid(), task_progress);
 
     updateState();
@@ -166,9 +166,9 @@ void ConcurrentTask::subTaskSucceeded(Task::Ptr task)
 
     disconnect(task.get(), 0, this, 0);
 
-    emit stepProgress(*task_progress.get());
+    emit stepProgress(*task_progress);
     updateState();
-    updateStepProgress(*task_progress.get(), Operation::REMOVED);
+    updateStepProgress(*task_progress, Operation::REMOVED);
     startNext();
 }
 
@@ -184,9 +184,9 @@ void ConcurrentTask::subTaskFailed(Task::Ptr task, const QString& msg)
 
     disconnect(task.get(), 0, this, 0);
 
-    emit stepProgress(*task_progress.get());
+    emit stepProgress(*task_progress);
     updateState();
-    updateStepProgress(*task_progress.get(), Operation::REMOVED);
+    updateStepProgress(*task_progress, Operation::REMOVED);
     startNext();
 }
 
@@ -196,7 +196,7 @@ void ConcurrentTask::subTaskStatus(Task::Ptr task, const QString& msg)
     task_progress->status = msg;
     task_progress->state = TaskStepState::Running;
     
-    emit stepProgress(*task_progress.get());
+    emit stepProgress(*task_progress);
 
     if (totalSize() == 1) {
         setStatus(msg);
@@ -209,7 +209,7 @@ void ConcurrentTask::subTaskDetails(Task::Ptr task, const QString& msg)
     task_progress->details = msg;
     task_progress->state = TaskStepState::Running;
     
-    emit stepProgress(*task_progress.get());
+    emit stepProgress(*task_progress);
 
     if (totalSize() == 1) {
         setDetails(msg);
@@ -220,15 +220,10 @@ void ConcurrentTask::subTaskProgress(Task::Ptr task, qint64 current, qint64 tota
 {
     auto task_progress = m_task_progress.value(task->getUid());
 
-    task_progress->old_current = task_progress->current;
-    task_progress->old_total = task_progress->old_total;
-
-    task_progress->current = current;
-    task_progress->total = total;
-    task_progress->state = TaskStepState::Running;
-    
-    emit stepProgress(*task_progress.get());
-    updateStepProgress(*task_progress.get(), Operation::CHANGED);
+    task_progress->update(current, total);
+        
+    emit stepProgress(*task_progress);
+    updateStepProgress(*task_progress, Operation::CHANGED);
     updateState();
 
     if (totalSize() == 1) {
diff --git a/launcher/tasks/Task.cpp b/launcher/tasks/Task.cpp
index b0addd46..29c55cd4 100644
--- a/launcher/tasks/Task.cpp
+++ b/launcher/tasks/Task.cpp
@@ -109,7 +109,7 @@ void Task::start()
             return;
         }
     }
-    // NOTE: only fall thorugh to here in end states
+    // NOTE: only fall through to here in end states
     m_state = State::Running;
     emit started();
     executeTask();
diff --git a/launcher/tasks/Task.h b/launcher/tasks/Task.h
index 799ed945..6d8bbbb4 100644
--- a/launcher/tasks/Task.h
+++ b/launcher/tasks/Task.h
@@ -64,7 +64,21 @@ struct TaskStepProgress {
     QString status = "";
     QString details = "";
     TaskStepState state = TaskStepState::Waiting;
+    TaskStepProgress() {
+        this->uid = QUuid::createUuid();
+    }
+    TaskStepProgress(QUuid uid) {
+        this->uid = uid;
+    }
     bool isDone() const { return (state == TaskStepState::Failed) || (state == TaskStepState::Succeeded); }
+    void update(qint64 current, qint64 total) {
+        this->old_current = this->current;
+        this->old_total = this->total;
+
+        this->current = current;
+        this->total = total;
+        this->state = TaskStepState::Running;
+    }
 };
 
 Q_DECLARE_METATYPE(TaskStepProgress)
-- 
cgit