Commit 4f7c2c7f by Jonathan Wakely Committed by Jonathan Wakely

Fix memory leaks in libstdc++ ABI tests

	* testsuite/abi/pr42230.cc: Free memory.
	* testsuite/util/testsuite_abi.cc (demangle): Return std::string
	instead of pointer that might need freeing.
	* testsuite/util/testsuite_abi.h (demangle): Likewise.
	* testsuite/util/testsuite_hooks.cc (verify_demangle): Free memory.

From-SVN: r250020
parent 318c48e3
2017-07-06 Jonathan Wakely <jwakely@redhat.com> 2017-07-06 Jonathan Wakely <jwakely@redhat.com>
* testsuite/abi/pr42230.cc: Free memory.
* testsuite/util/testsuite_abi.cc (demangle): Return std::string
instead of pointer that might need freeing.
* testsuite/util/testsuite_abi.h (demangle): Likewise.
* testsuite/util/testsuite_hooks.cc (verify_demangle): Free memory.
* include/bits/uses_allocator.h (__use_alloc(const _Alloc&&)): Add * include/bits/uses_allocator.h (__use_alloc(const _Alloc&&)): Add
deleted overload to prevent dangling references to rvalues. deleted overload to prevent dangling references to rvalues.
* include/experimental/memory_resource * include/experimental/memory_resource
......
...@@ -12,5 +12,6 @@ int main() ...@@ -12,5 +12,6 @@ int main()
char* ret = abi::__cxa_demangle("e", 0, &length, &cc); char* ret = abi::__cxa_demangle("e", 0, &length, &cc);
assert( (cc < 0 && !ret) || (ret && length) ); assert( (cc < 0 && !ret) || (ret && length) );
std::free(ret);
return 0; return 0;
} }
...@@ -590,21 +590,26 @@ create_symbols(const char* file) ...@@ -590,21 +590,26 @@ create_symbols(const char* file)
} }
const char* std::string
demangle(const std::string& mangled) demangle(const std::string& mangled)
{ {
const char* name; std::string name;
if (mangled[0] != '_' || mangled[1] != 'Z') if (mangled[0] != '_' || mangled[1] != 'Z')
{ {
// This is not a mangled symbol, thus has "C" linkage. // This is not a mangled symbol, thus has "C" linkage.
name = mangled.c_str(); name = mangled;
} }
else else
{ {
// Use __cxa_demangle to demangle. // Use __cxa_demangle to demangle.
int status = 0; int status = 0;
name = abi::__cxa_demangle(mangled.c_str(), 0, 0, &status); char* ptr = abi::__cxa_demangle(mangled.c_str(), 0, 0, &status);
if (!name) if (ptr)
{
name = ptr;
free(ptr);
}
else
{ {
switch (status) switch (status)
{ {
......
...@@ -94,5 +94,5 @@ compare_symbols(const char* baseline_file, const char* test_file, bool verb); ...@@ -94,5 +94,5 @@ compare_symbols(const char* baseline_file, const char* test_file, bool verb);
symbols symbols
create_symbols(const char* file); create_symbols(const char* file);
const char* std::string
demangle(const std::string& mangled); demangle(const std::string& mangled);
...@@ -131,8 +131,11 @@ namespace __gnu_test ...@@ -131,8 +131,11 @@ namespace __gnu_test
verify_demangle(const char* mangled, const char* wanted) verify_demangle(const char* mangled, const char* wanted)
{ {
int status = 0; int status = 0;
const char* s = abi::__cxa_demangle(mangled, 0, 0, &status); const char* s = 0;
if (!s) char* demangled = abi::__cxa_demangle(mangled, 0, 0, &status);
if (demangled)
s = demangled;
else
{ {
switch (status) switch (status)
{ {
...@@ -156,6 +159,7 @@ namespace __gnu_test ...@@ -156,6 +159,7 @@ namespace __gnu_test
std::string w(wanted); std::string w(wanted);
if (w != s) if (w != s)
std::__throw_runtime_error(s); std::__throw_runtime_error(s);
free(demangled);
} }
void void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment