public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Project Archer <archer@sourceware.org>
Subject: [expr-cumulative] FYI: avoid memory leak
Date: Wed, 10 Feb 2010 19:03:00 -0000	[thread overview]
Message-ID: <m3fx58ykuy.fsf@fleche.redhat.com> (raw)

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,

                 reply	other threads:[~2010-02-10 19:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3fx58ykuy.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=archer@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).