From 3173d025389ec4bd0edec7e06cdae2e47484b807 Mon Sep 17 00:00:00 2001 From: Gonglja <39959756+Gonglja@users.noreply.github.com> Date: Sun, 19 Mar 2023 23:46:48 +0800 Subject: [PATCH] fix(codes/cpp): Memory leak fix: the space was not freed when pop removed the element. (#423) --- codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp b/codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp index 1bbccc48c..76a10cbd5 100644 --- a/codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp +++ b/codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp @@ -92,6 +92,7 @@ public: if (fNext != nullptr) { fNext->prev = nullptr; front->next = nullptr; + delete front; } front = fNext; // 更新头结点 // 队尾出队操作 @@ -102,6 +103,7 @@ public: if (rPrev != nullptr) { rPrev->next = nullptr; rear->prev = nullptr; + delete rear; } rear = rPrev; // 更新尾结点 }