* 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
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
char* ret = abi::__cxa_demangle("e", 0, &length, &cc);
assert( (cc < 0 && !ret) || (ret && length) );
+ std::free(ret);
return 0;
}
}
-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)
{
symbols
create_symbols(const char* file);
-const char*
+std::string
demangle(const std::string& mangled);
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)
{
std::string w(wanted);
if (w != s)
std::__throw_runtime_error(s);
+ free(demangled);
}
void