Remove memory leaks in libstdc++ testsuite
authorJonathan Wakely <jwakely@redhat.com>
Thu, 21 Jul 2016 19:38:32 +0000 (20:38 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Thu, 21 Jul 2016 19:38:32 +0000 (20:38 +0100)
* 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
libstdc++-v3/testsuite/18_support/new_delete_placement.cc
libstdc++-v3/testsuite/20_util/addressof/1.cc
libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/3.cc
libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/55028-debug.cc

index 8e6f66bc31b0a35aab509e84e92550768df44892..d928c65e73d14b7314a806b05c821dba2b9509e7 100644 (file)
@@ -1,3 +1,12 @@
+2016-07-21  Jonathan Wakely  <jwakely@redhat.com>
+
+       * 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  <jwakely@redhat.com>
 
        * doc/xml/manual/intro.xml: Document DR 2684 status.
index 2c4607be52d166221528f741d6c987ad464fc42a..9049dca6083cd8ba369650320c7a44d6196bcfcb 100644 (file)
 // 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()
index 7208fc4e25d3605f42a8d10cf6c428828a505e9a..732eebcb2c5736fda9e3d2ba3d75c72d6a6821c9 100644 (file)
@@ -41,6 +41,9 @@ void test01()
   VERIFY( std::addressof(o2) == ao2 );
 
   VERIFY( std::addressof(f1) == &f1 );
+
+  delete ao1;
+  delete ao2;
 }
 
 int main()
index 0eb656c402efa7f31f3f710ab5bd35aa864dafa2..ec33614e31404f8eda025b9c3f25fac638fe537d 100644 (file)
@@ -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);
 }
index 65830add220dd5680b1224330836422031c994d8..e7afc8fdcaef3678a633522dd49c0ee74ce838bf 100644 (file)
@@ -30,7 +30,7 @@ void test()
   // using MyMap = std::multimap<std::string, MyType *>; // works
   using MyMap = std::unordered_multimap<std::string, MyType*>; // 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()