public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] sim: Be sure of calling freeargv() after successfully call buildargv().
@ 2015-01-28 15:53 Chen Gang S
  2015-01-28 20:43 ` Michael Eager
  2015-01-29  7:03 ` Joel Brobecker
  0 siblings, 2 replies; 19+ messages in thread
From: Chen Gang S @ 2015-01-28 15:53 UTC (permalink / raw)
  To: gdb-patches; +Cc: binutils

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)

^ permalink raw reply	[flat|nested] 19+ messages in thread
* [PATCH] sim: Be sure of calling freeargv() after successfully call buildargv().
@ 2015-01-31  8:59 Chen Gang S
  0 siblings, 0 replies; 19+ messages in thread
From: Chen Gang S @ 2015-01-31  8:59 UTC (permalink / raw)
  To: gdb-patches

Or there will be memory leak.

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

	* mcore/interp.c (sim_do_command): Call freeargv() before return.
---
 sim/ChangeLog      | 4 ++++
 sim/mcore/interp.c | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/sim/ChangeLog b/sim/ChangeLog
index 7153c6a..1fe93df 100644
--- a/sim/ChangeLog
+++ b/sim/ChangeLog
@@ -1,5 +1,9 @@
 2014-01-31  Chen Gang <gang.chen.5i5j@gmail.com>
 
+	* mcore/interp.c (sim_do_command): Call freeargv() before return.
+
+2014-01-31  Chen Gang <gang.chen.5i5j@gmail.com>
+
 	* common/sim-options.c (sim_args_command): Call freeargv() when
 	failure occurs.
 
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
     {
-- 
1.9.3

^ permalink raw reply	[flat|nested] 19+ messages in thread
* [PATCH] sim: Be sure of calling freeargv() after successfully call buildargv().
@ 2015-01-31 11:56 Chen Gang S
  2015-01-31 18:46 ` Michael Eager
  2015-02-17 10:34 ` Mike Frysinger
  0 siblings, 2 replies; 19+ messages in thread
From: Chen Gang S @ 2015-01-31 11:56 UTC (permalink / raw)
  To: gdb-patches

Or there will be memory leak.

2014-01-31  Chen Gang <gang.chen.5i5j@gmail.com>

	* microblaze/interp.c (sim_do_command): Call freeargv() before
	return.
---
 sim/ChangeLog           | 5 +++++
 sim/microblaze/interp.c | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/sim/ChangeLog b/sim/ChangeLog
index 1fe93df..582bd4a 100644
--- a/sim/ChangeLog
+++ b/sim/ChangeLog
@@ -1,5 +1,10 @@
 2014-01-31  Chen Gang <gang.chen.5i5j@gmail.com>
 
+	* microblaze/interp.c (sim_do_command): Call freeargv() before
+	return.
+
+2014-01-31  Chen Gang <gang.chen.5i5j@gmail.com>
+
 	* mcore/interp.c (sim_do_command): Call freeargv() before return.
 
 2014-01-31  Chen Gang <gang.chen.5i5j@gmail.com>
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

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2015-02-19 15:53 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-28 15:53 [PATCH] sim: Be sure of calling freeargv() after successfully call buildargv() Chen Gang S
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

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