* [PATCH] Fix memory leaks in libstdc++ ABI tests
@ 2017-07-06 12:42 Jonathan Wakely
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2017-07-06 12:42 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 440 bytes --]
These tests don't bother to free memory before exit, but that means we
get ASan errors for them. Fixed like so.
* 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.
Tested powerpc64le-linux, committed to trunk.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 3015 bytes --]
commit 6442c85d107824319d19b36799682335d8133689
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Wed Jul 20 22:49:44 2016 +0100
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.
diff --git a/libstdc++-v3/testsuite/abi/pr42230.cc b/libstdc++-v3/testsuite/abi/pr42230.cc
index 2a33899..3b5a1f6 100644
--- a/libstdc++-v3/testsuite/abi/pr42230.cc
+++ b/libstdc++-v3/testsuite/abi/pr42230.cc
@@ -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;
}
diff --git a/libstdc++-v3/testsuite/util/testsuite_abi.cc b/libstdc++-v3/testsuite/util/testsuite_abi.cc
index 4d7f4ca..d18429a 100644
--- a/libstdc++-v3/testsuite/util/testsuite_abi.cc
+++ b/libstdc++-v3/testsuite/util/testsuite_abi.cc
@@ -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)
{
diff --git a/libstdc++-v3/testsuite/util/testsuite_abi.h b/libstdc++-v3/testsuite/util/testsuite_abi.h
index 8275b23..77c5656 100644
--- a/libstdc++-v3/testsuite/util/testsuite_abi.h
+++ b/libstdc++-v3/testsuite/util/testsuite_abi.h
@@ -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);
diff --git a/libstdc++-v3/testsuite/util/testsuite_hooks.cc b/libstdc++-v3/testsuite/util/testsuite_hooks.cc
index d1063e3..74e755d 100644
--- a/libstdc++-v3/testsuite/util/testsuite_hooks.cc
+++ b/libstdc++-v3/testsuite/util/testsuite_hooks.cc
@@ -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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix memory leaks in libstdc++ ABI tests
2017-07-10 18:32 David Edelsohn
@ 2017-07-10 18:43 ` Jonathan Wakely
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2017-07-10 18:43 UTC (permalink / raw)
To: David Edelsohn; +Cc: GCC Patches, libstdc++
[-- Attachment #1: Type: text/plain, Size: 393 bytes --]
On 10/07/17 14:32 -0400, David Edelsohn wrote:
>The memory leak cleanup has introduced a testsuite failure on AIX:
>
>/nasfarm/edelsohn/src/src/libstdc++-v3/testsuite/abi/pr42230.cc: In
>function 'int main()':
>/nasfarm/edelsohn/src/src/libstdc++-v3/testsuite/abi/pr42230.cc:15:
>error: 'free' is not a member of 'std'
>compiler exited with status 1
This should fix it, committed to trunk.
[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 562 bytes --]
commit 889654aceb34ef6748d23c062325b6b45a93737c
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon Jul 10 19:35:56 2017 +0100
Include missing header for std::free
* testsuite/abi/pr42230.cc: Add header for std::free.
diff --git a/libstdc++-v3/testsuite/abi/pr42230.cc b/libstdc++-v3/testsuite/abi/pr42230.cc
index 3b5a1f6..48156e4 100644
--- a/libstdc++-v3/testsuite/abi/pr42230.cc
+++ b/libstdc++-v3/testsuite/abi/pr42230.cc
@@ -3,6 +3,7 @@
#include <cxxabi.h>
#include <cassert>
#include <cstddef>
+#include <cstdlib>
int main()
{
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix memory leaks in libstdc++ ABI tests
@ 2017-07-10 18:32 David Edelsohn
2017-07-10 18:43 ` Jonathan Wakely
0 siblings, 1 reply; 3+ messages in thread
From: David Edelsohn @ 2017-07-10 18:32 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: GCC Patches, libstdc++
The memory leak cleanup has introduced a testsuite failure on AIX:
/nasfarm/edelsohn/src/src/libstdc++-v3/testsuite/abi/pr42230.cc: In
function 'int main()':
/nasfarm/edelsohn/src/src/libstdc++-v3/testsuite/abi/pr42230.cc:15:
error: 'free' is not a member of 'std'
compiler exited with status 1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-07-10 18:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-06 12:42 [PATCH] Fix memory leaks in libstdc++ ABI tests Jonathan Wakely
2017-07-10 18:32 David Edelsohn
2017-07-10 18:43 ` Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).