diff options
| author | Eric Fiselier <eric@efcs.ca> | 2019-07-11 23:13:38 +0000 |
|---|---|---|
| committer | Eric Fiselier <eric@efcs.ca> | 2019-07-11 23:13:38 +0000 |
| commit | 41798c05cd20401b3f77d12b8bfcb0437132021f (patch) | |
| tree | 7cc2e4424b6e3dc941421df29e7d90adc5ac2369 /libcxx/test/std/containers/associative/set | |
| parent | 6f8f1a7db7b23dfa30d8de9df9450d8355475974 (diff) | |
| download | bcm5719-llvm-41798c05cd20401b3f77d12b8bfcb0437132021f.tar.gz bcm5719-llvm-41798c05cd20401b3f77d12b8bfcb0437132021f.zip | |
Fix memory leak in set and map.
When assigning an initializer list into set/map, libc++ would
leak memory if the initializer list contained equivalent keys
because we failed to check if the insertion was successful.
llvm-svn: 365840
Diffstat (limited to 'libcxx/test/std/containers/associative/set')
| -rw-r--r-- | libcxx/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/libcxx/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp index e04f49c9993..3762446467e 100644 --- a/libcxx/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp +++ b/libcxx/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp @@ -16,13 +16,14 @@ #include <set> #include <cassert> +#include <iostream> #include "test_macros.h" #include "min_allocator.h" +#include "test_allocator.h" -int main(int, char**) -{ - { +void basic_test() { + { typedef std::set<int> C; typedef C::value_type V; C m = {10, 8}; @@ -36,9 +37,9 @@ int main(int, char**) assert(*++i == V(4)); assert(*++i == V(5)); assert(*++i == V(6)); - } - { - typedef std::set<int, std::less<int>, min_allocator<int>> C; + } + { + typedef std::set<int, std::less<int>, min_allocator<int> > C; typedef C::value_type V; C m = {10, 8}; m = {1, 2, 3, 4, 5, 6}; @@ -51,7 +52,27 @@ int main(int, char**) assert(*++i == V(4)); assert(*++i == V(5)); assert(*++i == V(6)); - } + } +} + +void duplicate_keys_test() { + typedef std::set<int, std::less<int>, test_allocator<int> > Set; + typedef test_alloc_base AllocBase; + { + LIBCPP_ASSERT(AllocBase::alloc_count == 0); + Set s = {1, 2, 3}; + LIBCPP_ASSERT(AllocBase::alloc_count == 3); + s = {4, 4, 4, 4, 4}; + LIBCPP_ASSERT(AllocBase::alloc_count == 1); + assert(s.size() == 1); + assert(*s.begin() == 4); + } + LIBCPP_ASSERT(AllocBase::alloc_count == 0); +} + +int main(int, char**) { + basic_test(); + duplicate_keys_test(); return 0; } |

