This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
[expr-cumulative] FYI: avoid memory leak
- From: Tom Tromey <tromey at redhat dot com>
- To: Project Archer <archer at sourceware dot org>
- Date: Wed, 10 Feb 2010 12:03:01 -0700
- Subject: [expr-cumulative] FYI: avoid memory leak
- Reply-to: tromey at redhat dot com
I'm checking this in on the expr-cumulative as obvious.
This avoids a memory leak in the C lexer.
Tom
2010-02-10 Tom Tromey <tromey@redhat.com>
* c-exp.y (yylex): Use alloca, not savestring.
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 459177a..f8c23e0 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -2447,7 +2447,11 @@ yylex (void)
int hextype;
if (name_prefix != NULL)
- tmp = savestring (name_prefix, name_prefix_len+namelen);
+ {
+ tmp = alloca (name_prefix_len + namelen + 1);
+ memcpy (tmp, name_prefix, name_prefix_len + namelen);
+ tmp[name_prefix_len + namelen] = '\0';
+ }
sym = lookup_symbol (tmp, expression_context_block,
VAR_DOMAIN,