mirror of
				https://github.com/krahets/hello-algo.git
				synced 2025-11-04 06:07:20 +08:00 
			
		
		
		
	fix(codes/cpp): Memory leak fix: the space was not freed when pop removed the element. (#423)
This commit is contained in:
		@ -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;    // 更新尾结点
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user