This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] Delete temporary string within demangler even in failure cases.
- From: Andrew Burgess <aburgess at broadcom dot com>
- To: <gcc-patches at gcc dot gnu dot org>
- Cc: <gdb-patches at sourceware dot org>, Andrew Burgess <aburgess at broadcom dot com>
- Date: Tue, 27 May 2014 11:57:33 +0100
- Subject: [PATCH] Delete temporary string within demangler even in failure cases.
- Authentication-results: sourceware.org; auth=none
Spotted that a call to demangle_template might allocate storage within a
temporary string even if the call to demangle_template eventually returns
failure.
This will never cause the demangler to crash, but does leak memory, as a
result I've not added any tests for this.
Calling string_delete is safe, even if nothing is allocated into the
string, the string is initialised with string_init, so we know the internal
pointers are NULL.
I don't have gcc write privilages, so if this is approved could someone
please commit for me.
Thanks,
Andrew
libiberty/ChangeLog
* cplus-dem.c (do_type): Call string_delete even if the call to
demangle_template fails.
---
libiberty/cplus-dem.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/libiberty/cplus-dem.c b/libiberty/cplus-dem.c
index e948487..1c713aa 100644
--- a/libiberty/cplus-dem.c
+++ b/libiberty/cplus-dem.c
@@ -3656,7 +3656,10 @@ do_type (struct work_stuff *work, const char **mangled, string *result)
string_delete (&temp);
}
else
- break;
+ {
+ string_delete (&temp);
+ break;
+ }
}
else if (**mangled == 'Q')
{
--
1.8.1.3