fix(codes/cpp): Memory leak fix: the space was not freed when pop removed the element. (#423)

pull/429/head^2
Gonglja 2 years ago committed by GitHub
parent ceeb138487
commit 3173d02538
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -92,6 +92,7 @@ public:
if (fNext != nullptr) { if (fNext != nullptr) {
fNext->prev = nullptr; fNext->prev = nullptr;
front->next = nullptr; front->next = nullptr;
delete front;
} }
front = fNext; // 更新头结点 front = fNext; // 更新头结点
// 队尾出队操作 // 队尾出队操作
@ -102,6 +103,7 @@ public:
if (rPrev != nullptr) { if (rPrev != nullptr) {
rPrev->next = nullptr; rPrev->next = nullptr;
rear->prev = nullptr; rear->prev = nullptr;
delete rear;
} }
rear = rPrev; // 更新尾结点 rear = rPrev; // 更新尾结点
} }

Loading…
Cancel
Save