Copilot: correctly cleanup compression timer

fixes a leak and a crash if the timer triggers after the widget was
deleted.

Change-Id: I57794009186d4c5e4dee0b0c0746ffc5468000b7
Reviewed-by: Artem Sokolovskii <artem.sokolovskii@qt.io>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
David Schulz
2023-03-24 11:27:21 +01:00
parent 1be65dd1ee
commit e6e895d6be
2 changed files with 6 additions and 0 deletions

View File

@@ -108,6 +108,11 @@ void CopilotClient::scheduleRequest(TextEditorWidget *editor)
m_scheduledRequests[editor].timer->start(500);
}
CopilotClient::ScheduleData::~ScheduleData()
{
delete timer;
}
void CopilotClient::requestCompletions(TextEditorWidget *editor)
{
Utils::MultiTextCursor cursor = editor->multiTextCursor();

View File

@@ -50,6 +50,7 @@ private:
QMap<TextEditor::TextEditorWidget *, GetCompletionRequest> m_runningRequests;
struct ScheduleData
{
~ScheduleData();
int cursorPosition = -1;
QTimer *timer = nullptr;
};