Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: gdb-patches@sourceware.org
Subject: RFA: fix memory leak in "source" command
Date: Mon, 10 Nov 2008 19:45:00 -0000	[thread overview]
Message-ID: <m3myg7jrtm.fsf@fleche.redhat.com> (raw)

Valgrind pointed out that the "source" command leaks full_pathname.

The fix is to add a cleanup for it.  This patch also makes sure to run
the cleanups on early return from the function.

Built and regested on x86-64 (compile farm).
Ok?

Tom

:ADDPATCH cli:

2008-11-10  Tom Tromey  <tromey@redhat.com>

	* cli/cli-cmds.c (source_script): Clean up full_pathname.  Run
	cleanups on early return.

diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index d9d2c56..21a64a0 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -450,6 +450,7 @@ source_script (char *file, int from_tty)
      files.  Put the full location in 'full_pathname'.  */
   fd = openp (source_path, OPF_TRY_CWD_FIRST,
 	      file, O_RDONLY, 0, &full_pathname);
+  make_cleanup (xfree, full_pathname);
 
   /* Use the full path name, if it is found.  */
   if (full_pathname != NULL && fd != -1)
@@ -462,7 +463,10 @@ source_script (char *file, int from_tty)
       if (from_tty)
 	perror_with_name (file);
       else
-	return;
+	{
+	  do_cleanups (old_cleanups);
+	  return;
+	}
     }
 
   stream = fdopen (fd, FOPEN_RT);


             reply	other threads:[~2008-11-10 19:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-10 19:45 Tom Tromey [this message]
2008-11-10 20:50 ` Pedro Alves

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=m3myg7jrtm.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=gdb-patches@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