public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
* [expr-cumulative] FYI: avoid memory leak
@ 2010-02-10 19:03 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2010-02-10 19:03 UTC (permalink / raw)
  To: Project Archer

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,

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-02-10 19:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-10 19:03 [expr-cumulative] FYI: avoid memory leak Tom Tromey

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).