From 23d498f68a00344dac6f0698effe4b57111b7675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Fri, 2 Jan 2015 13:14:02 +0800 Subject: [PATCH] bug fix --- TinySTL/BinarySearchTree.h | 1 + TinySTL/Deque.h | 12 +++++++++--- TinySTL/List.h | 4 +++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/TinySTL/BinarySearchTree.h b/TinySTL/BinarySearchTree.h index ddd789c..bd6d282 100644 --- a/TinySTL/BinarySearchTree.h +++ b/TinySTL/BinarySearchTree.h @@ -72,6 +72,7 @@ namespace TinySTL{ if (ptr){ deallocateAllNodes(ptr->left_); deallocateAllNodes(ptr->right_); + nodeAllocator::destroy(ptr); nodeAllocator::deallocate(ptr); } } diff --git a/TinySTL/Deque.h b/TinySTL/Deque.h index bdea849..549559c 100644 --- a/TinySTL/Deque.h +++ b/TinySTL/Deque.h @@ -189,9 +189,12 @@ namespace TinySTL{ deque(const deque& x); ~deque(){ - for (int i = 0; i != mapSize_; ++i) + for (int i = 0; i != mapSize_; ++i){ + for (auto p = map_[i] + 0; !p && p != map_[i] + getBuckSize(); ++p) + dataAllocator::destroy(p); if (!map_[i]) dataAllocator::deallocate(map_[i], getBuckSize()); + } delete[] map_; } @@ -221,9 +224,12 @@ namespace TinySTL{ void pop_front(); void swap(deque& x); void clear(){ - for (int i = 0; i != mapSize_; ++i) + /*for (int i = 0; i != mapSize_; ++i) if (!map_[i]) - dataAllocator::destroy(map_[i], map_[i] + getBuckSize()); + dataAllocator::destroy(map_[i], map_[i] + getBuckSize());*/ + for (auto i = 0; i != mapSize_; ++i){ + for (auto p = map_[i] + 0; !p && p != map_[i] + getBuckSize(); ++p) + dataAllocator::destroy(p); mapSize_ = 0; beg_.mapIndex_ = end_.mapIndex_ = mapSize_ / 2; beg_.cur_ = end_.cur_ = map_[mapSize_ / 2]; diff --git a/TinySTL/List.h b/TinySTL/List.h index e5d8b6c..f61971c 100644 --- a/TinySTL/List.h +++ b/TinySTL/List.h @@ -116,6 +116,8 @@ namespace TinySTL{ ~list(){ for (; head != tail;){ auto temp = head++; + //bug fix + nodeAllocator::destroy(temp.p); nodeAllocator::deallocate(temp.p); } nodeAllocator::deallocate(tail.p); @@ -185,7 +187,7 @@ namespace TinySTL{ nodePtr res = nodeAllocator::allocate(); res->container = this; //res->data = val; -> bug - construct(&(res->data), val);//fix + nodeAllocator::construct(&(res->data), val);//fix res->prev = nullptr; res->next = nullptr; return res;