From 22620c14525becbb209ae95ca2ff46412d7c10c6 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Thu, 21 Jul 2016 20:38:32 +0100 Subject: [PATCH] Remove memory leaks in libstdc++ testsuite * testsuite/18_support/new_delete_placement.cc: Don't allocate (and leak) memory for arguments to placement delete. * testsuite/20_util/addressof/1.cc: Don't leak memory. * testsuite/22_locale/locale/global_locale_objects/3.cc: Likewise. * testsuite/23_containers/unordered_multimap/insert/55028-debug.cc: Likewise. From-SVN: r238607 --- libstdc++-v3/ChangeLog | 9 +++++++++ .../testsuite/18_support/new_delete_placement.cc | 8 ++++---- libstdc++-v3/testsuite/20_util/addressof/1.cc | 3 +++ .../22_locale/locale/global_locale_objects/3.cc | 9 +++++++-- .../unordered_multimap/insert/55028-debug.cc | 2 +- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 8e6f66bc31b..d928c65e73d 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2016-07-21 Jonathan Wakely + + * testsuite/18_support/new_delete_placement.cc: Don't allocate (and + leak) memory for arguments to placement delete. + * testsuite/20_util/addressof/1.cc: Don't leak memory. + * testsuite/22_locale/locale/global_locale_objects/3.cc: Likewise. + * testsuite/23_containers/unordered_multimap/insert/55028-debug.cc: + Likewise. + 2016-07-20 Jonathan Wakely * doc/xml/manual/intro.xml: Document DR 2684 status. diff --git a/libstdc++-v3/testsuite/18_support/new_delete_placement.cc b/libstdc++-v3/testsuite/18_support/new_delete_placement.cc index 2c4607be52d..9049dca6083 100644 --- a/libstdc++-v3/testsuite/18_support/new_delete_placement.cc +++ b/libstdc++-v3/testsuite/18_support/new_delete_placement.cc @@ -25,11 +25,11 @@ // libstdc++/7286 void test01() { - void* pc = new char; - void* pa = new char[10]; + char c = 'c'; + void* p = &c; void* tmp = 0; - operator delete(pc, tmp); - operator delete[](pa, tmp); + operator delete(p, tmp); + operator delete[](p, tmp); } int main() diff --git a/libstdc++-v3/testsuite/20_util/addressof/1.cc b/libstdc++-v3/testsuite/20_util/addressof/1.cc index 7208fc4e25d..732eebcb2c5 100644 --- a/libstdc++-v3/testsuite/20_util/addressof/1.cc +++ b/libstdc++-v3/testsuite/20_util/addressof/1.cc @@ -41,6 +41,9 @@ void test01() VERIFY( std::addressof(o2) == ao2 ); VERIFY( std::addressof(f1) == &f1 ); + + delete ao1; + delete ao2; } int main() diff --git a/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/3.cc b/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/3.cc index 0eb656c402e..ec33614e314 100644 --- a/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/3.cc +++ b/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/3.cc @@ -73,13 +73,15 @@ void test03() VERIFY( loc04 == global_orig ); } - // 2: Not destroyed when out of scope, deliberately leaked. + // 2: Not destroyed when out of scope, deliberately "leaked". + const facet_type* ptr = 0; { { { VERIFY( counter == 0 ); { - locale loc01(locale::classic(), new facet_type(1)); + ptr = new facet_type(1); + locale loc01(locale::classic(), ptr); VERIFY( counter == 1 ); global_orig = locale::global(loc01); name = loc01.name(); @@ -101,6 +103,9 @@ void test03() } VERIFY( counter == 1 ); + // Clean up. + delete ptr; + // Restore global settings. locale::global(global_orig); } diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/55028-debug.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/55028-debug.cc index 65830add220..e7afc8fdcae 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/55028-debug.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/55028-debug.cc @@ -30,7 +30,7 @@ void test() // using MyMap = std::multimap; // works using MyMap = std::unordered_multimap; // fails to link MyMap m; - m.insert(std::make_pair(std::string("blah"), new MyType)); + m.insert(std::make_pair(std::string("blah"), (MyType*)nullptr)); } int main()