[v2] sim: Be sure of calling freeargv() after successfully call buildargv().

Message ID 54CFDAF2.5050904@sunrus.com.cn
State Committed
Headers

Commit Message

Chen Gang Feb. 2, 2015, 8:15 p.m. UTC
  Or there will be memory leak.

2015-02-02  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(+)
  

Comments

Michael Eager Feb. 2, 2015, 8:16 p.m. UTC | #1
On 02/02/15 12:16, Chen Gang S wrote:
>
> If there will be no any additional reply within this week, I shall apply
> the related 3 patches to main branch.
>
> Thanks.
>
> On 2/3/15 04:15, Chen Gang S wrote:
>> Or there will be memory leak.
>>
>> 2015-02-02  Chen Gang <gang.chen.5i5j@gmail.com>
>>
>> 	* microblaze/interp.c (sim_do_command): Call freeargv() before

OK to apply.
  
Chen Gang Feb. 2, 2015, 8:16 p.m. UTC | #2
If there will be no any additional reply within this week, I shall apply
the related 3 patches to main branch.

Thanks.

On 2/3/15 04:15, Chen Gang S wrote:
> Or there will be memory leak.
> 
> 2015-02-02  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 @@
>  2015-02-02  Chen Gang <gang.chen.5i5j@gmail.com>
>  
> +	* microblaze/interp.c (sim_do_command): Call freeargv() before
> +	return.
> +
> +2015-02-02  Chen Gang <gang.chen.5i5j@gmail.com>
> +
>  	* mcore/interp.c (sim_do_command): Call freeargv() before return.
>  
>  2015-02-02  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
>      {
>
  
Chen Gang Feb. 2, 2015, 8:30 p.m. UTC | #3
On 2/3/15 04:16, Michael Eager wrote:
> On 02/02/15 12:16, Chen Gang S wrote:
>>
>> If there will be no any additional reply within this week, I shall apply
>> the related 3 patches to main branch.
>>
>> Thanks.
>>
>> On 2/3/15 04:15, Chen Gang S wrote:
>>> Or there will be memory leak.
>>>
>>> 2015-02-02  Chen Gang <gang.chen.5i5j@gmail.com>
>>>
>>>     * microblaze/interp.c (sim_do_command): Call freeargv() before
> 
> OK to apply.
> 

OK, thank. Finish "git push" for the related 3 patches.
  

Patch

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