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
This commit is contained in:
parent
318c48e304
commit
4f7c2c7ff2
|
@ -1,5 +1,11 @@
|
|||
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
|
||||
deleted overload to prevent dangling references to rvalues.
|
||||
* include/experimental/memory_resource
|
||||
|
|
|
@ -12,5 +12,6 @@ int main()
|
|||
char* ret = abi::__cxa_demangle("e", 0, &length, &cc);
|
||||
|
||||
assert( (cc < 0 && !ret) || (ret && length) );
|
||||
std::free(ret);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -590,21 +590,26 @@ create_symbols(const char* file)
|
|||
}
|
||||
|
||||
|
||||
const char*
|
||||
std::string
|
||||
demangle(const std::string& mangled)
|
||||
{
|
||||
const char* name;
|
||||
std::string name;
|
||||
if (mangled[0] != '_' || mangled[1] != 'Z')
|
||||
{
|
||||
// This is not a mangled symbol, thus has "C" linkage.
|
||||
name = mangled.c_str();
|
||||
name = mangled;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use __cxa_demangle to demangle.
|
||||
int status = 0;
|
||||
name = abi::__cxa_demangle(mangled.c_str(), 0, 0, &status);
|
||||
if (!name)
|
||||
char* ptr = abi::__cxa_demangle(mangled.c_str(), 0, 0, &status);
|
||||
if (ptr)
|
||||
{
|
||||
name = ptr;
|
||||
free(ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
|
|
|
@ -94,5 +94,5 @@ compare_symbols(const char* baseline_file, const char* test_file, bool verb);
|
|||
symbols
|
||||
create_symbols(const char* file);
|
||||
|
||||
const char*
|
||||
std::string
|
||||
demangle(const std::string& mangled);
|
||||
|
|
|
@ -131,8 +131,11 @@ namespace __gnu_test
|
|||
verify_demangle(const char* mangled, const char* wanted)
|
||||
{
|
||||
int status = 0;
|
||||
const char* s = abi::__cxa_demangle(mangled, 0, 0, &status);
|
||||
if (!s)
|
||||
const char* s = 0;
|
||||
char* demangled = abi::__cxa_demangle(mangled, 0, 0, &status);
|
||||
if (demangled)
|
||||
s = demangled;
|
||||
else
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
|
@ -156,6 +159,7 @@ namespace __gnu_test
|
|||
std::string w(wanted);
|
||||
if (w != s)
|
||||
std::__throw_runtime_error(s);
|
||||
free(demangled);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in New Issue