Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Chen Gang S <gang.chen@sunrus.com.cn>
To: gdb-patches@sourceware.org
Cc: binutils@sourceware.org
Subject: [PATCH] sim: Be sure of calling freeargv() after successfully call buildargv().
Date: Wed, 28 Jan 2015 15:53:00 -0000	[thread overview]
Message-ID: <54C8CBC8.90102@sunrus.com.cn> (raw)

buildargv() and freeargv() are pairs, so need be sure of them always
paired to avoid memory leak.

2015-01-28  Chen Gang <gang.chen.5i5j@gmail.com>

	* common/sim-options.c (sim_args_command): Call freeargv() when
	failure occurs.
	* mcore/interp.c (sim_do_command): Call freeargv() before return.
	* microblaze/interp.c (sim_do_command): Call freeargv() before
	return.
---
 sim/ChangeLog            | 8 ++++++++
 sim/common/sim-options.c | 5 ++++-
 sim/mcore/interp.c       | 3 +++
 sim/microblaze/interp.c  | 3 +++
 4 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/sim/ChangeLog b/sim/ChangeLog
index 03c244b..a5c3f5d 100644
--- a/sim/ChangeLog
+++ b/sim/ChangeLog
@@ -1,3 +1,11 @@
+2015-01-28  Chen Gang <gang.chen.5i5j@gmail.com>
+
+	* common/sim-options.c (sim_args_command): Call freeargv() when
+	failure occurs.
+	* mcore/interp.c (sim_do_command): Call freeargv() before return.
+	* microblaze/interp.c (sim_do_command): Call freeargv() before
+	return.
+
 2014-07-01  Chen Gang <gang.chen.5i5j@gmail.com>
 
 	* sim/microblaze/interp.c: Use long int format instead of int
diff --git a/sim/common/sim-options.c b/sim/common/sim-options.c
index c49220e..814edcf 100644
--- a/sim/common/sim-options.c
+++ b/sim/common/sim-options.c
@@ -993,7 +993,10 @@ sim_args_command (SIM_DESC sd, const char *cmd)
       sim_cpu *cpu;
 
       if (argv [0] == NULL)
-	return SIM_RC_OK; /* FIXME - perhaps help would be better */
+	{
+	  freeargv (argv);
+	  return SIM_RC_OK; /* FIXME - perhaps help would be better */
+	}
 
       /* First check for a cpu selector.  */
       {
diff --git a/sim/mcore/interp.c b/sim/mcore/interp.c
index d2edd12..dfaa6aa 100644
--- a/sim/mcore/interp.c
+++ b/sim/mcore/interp.c
@@ -2143,6 +2143,7 @@ sim_do_command (sd, cmd)
 	  if ((simargv[1] == NULL) || (simargv[2] == NULL))
 	    {
 	      fprintf (stderr, "Error: missing argument to watch cmd.\n");
+	      freeargv (simargv);
 	      return;
 	    }
 	  
@@ -2187,6 +2188,8 @@ sim_do_command (sd, cmd)
 	  fprintf (stderr,"Error: \"%s\" is not a valid M.CORE simulator command.\n",
 		   cmd);
 	}
+
+      freeargv (simargv);
     }
   else
     {
diff --git a/sim/microblaze/interp.c b/sim/microblaze/interp.c
index 1c8a22d..4fc4595 100644
--- a/sim/microblaze/interp.c
+++ b/sim/microblaze/interp.c
@@ -1019,6 +1019,7 @@ sim_do_command (SIM_DESC sd, const char *cmd)
 	  if ((simargv[1] == NULL) || (simargv[2] == NULL))
 	    {
 	      fprintf (stderr, "Error: missing argument to watch cmd.\n");
+	      freeargv (simargv);
 	      return;
 	    }
 
@@ -1062,6 +1063,8 @@ sim_do_command (SIM_DESC sd, const char *cmd)
 	  fprintf (stderr,"Error: \"%s\" is not a valid M.CORE simulator command.\n",
 		   cmd);
 	}
+
+      freeargv (simargv);
     }
   else
     {
-- 
1.9.3 (Apple Git-50)


             reply	other threads:[~2015-01-28 11:37 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-28 15:53 Chen Gang S [this message]
2015-01-28 20:43 ` Michael Eager
2015-01-29  4:53   ` Chen Gang S
2015-01-29  5:01     ` Michael Eager
2015-01-29  5:11       ` Chen Gang S
2015-02-17 10:36     ` Mike Frysinger
2015-01-29  7:03 ` Joel Brobecker
2015-01-29  7:28   ` Chen Gang S
2015-01-31  8:59 Chen Gang S
2015-01-31 11:56 Chen Gang S
2015-01-31 18:46 ` Michael Eager
2015-02-02 19:38   ` Chen Gang S
2015-02-03  2:50     ` Joel Brobecker
2015-02-03  9:58       ` Chen Gang S
2015-02-17 10:34 ` Mike Frysinger
2015-02-17 23:10   ` Chen Gang S
2015-02-18  0:22     ` Mike Frysinger
2015-02-19  0:34       ` Chen Gang S
2015-02-19 15:53         ` Michael Eager

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=54C8CBC8.90102@sunrus.com.cn \
    --to=gang.chen@sunrus.com.cn \
    --cc=binutils@sourceware.org \
    --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