mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-24 10:36:29 +08:00
fix memory leak in the C code (#1203)
* fix memory leak when size(deque) == 1 * fix memory leak
This commit is contained in:
parent
0503e740ad
commit
db164f6703
2 changed files with 5 additions and 2 deletions
|
@ -49,6 +49,9 @@ void delHashMapOpenAddressing(HashMapOpenAddressing *hashMap) {
|
|||
free(pair);
|
||||
}
|
||||
}
|
||||
free(hashMap->buckets);
|
||||
free(hashMap->TOMBSTONE);
|
||||
free(hashMap);
|
||||
}
|
||||
|
||||
/* 哈希函数 */
|
||||
|
|
|
@ -122,8 +122,8 @@ int pop(LinkedListDeque *deque, bool isFront) {
|
|||
if (fNext) {
|
||||
fNext->prev = NULL;
|
||||
deque->front->next = NULL;
|
||||
delDoublyListNode(deque->front);
|
||||
}
|
||||
delDoublyListNode(deque->front);
|
||||
deque->front = fNext; // 更新头节点
|
||||
}
|
||||
// 队尾出队操作
|
||||
|
@ -133,8 +133,8 @@ int pop(LinkedListDeque *deque, bool isFront) {
|
|||
if (rPrev) {
|
||||
rPrev->next = NULL;
|
||||
deque->rear->prev = NULL;
|
||||
delDoublyListNode(deque->rear);
|
||||
}
|
||||
delDoublyListNode(deque->rear);
|
||||
deque->rear = rPrev; // 更新尾节点
|
||||
}
|
||||
deque->queSize--; // 更新队列长度
|
||||
|
|
Loading…
Reference in a new issue