fix memory leak in the C code (#1203)

* fix memory leak when size(deque) == 1

* fix memory leak
This commit is contained in:
Yang Le 2024-04-07 01:36:55 +08:00 committed by GitHub
parent 0503e740ad
commit db164f6703
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 2 deletions

View file

@ -49,6 +49,9 @@ void delHashMapOpenAddressing(HashMapOpenAddressing *hashMap) {
free(pair);
}
}
free(hashMap->buckets);
free(hashMap->TOMBSTONE);
free(hashMap);
}
/* 哈希函数 */

View file

@ -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--; // 更新队列长度