I've finally got the testsuite able to run with ubsan and asan
enabled, with a few hacks in place. That revealed quite a few
problems!
The first patch in this series just frees some memory which wasn't
being deallocated. That isn't really a problem, as the tests exit
immediately anyway, but it's nice to get clean reports from leak
checkers.
* 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.
Tested powerpc64-linux, committed to trunk.
commit 45bf3919ae2dbf9223f10c4dd854a13fd2ebc7ee
Author: Jonathan Wakely <[email protected]>
Date: Wed Jul 20 22:32:52 2016 +0100
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.
diff --git a/libstdc++-v3/testsuite/18_support/new_delete_placement.cc
b/libstdc++-v3/testsuite/18_support/new_delete_placement.cc
index 2c4607b..9049dca 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 7208fc4..732eebc 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 0eb656c..ec33614 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 65830ad..e7afc8f 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<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()