This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[expr-cumulative] FYI: avoid memory leak


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,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]