[OpenWrt-Devel] [PATCH rpcd v2 6/6] main: exec_self: make clang analyzer happy

Petr Štetiar ynezz at true.cz
Tue Oct 22 00:26:14 EDT 2019


Yousong Zhou <yszhou4tech at gmail.com> [2019-10-21 12:59:24]:

almost happy:

 main.c:65:1: warning: Potential leak of memory pointed to by 'args'

diff --git a/main.c b/main.c
index 12cb4c5c720c..8b11418f1c09 100644
--- a/main.c
+++ b/main.c
@@ -62,6 +62,7 @@ exec_self(int argc, char **argv)
 
 	setenv("RPC_HANGUP", "1", 1);
 	execv(cmd, (char * const *)args);
+	free(args);
 }

> Signed-off-by: Yousong Zhou <yszhou4tech at gmail.com>
> ---
>  main.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/main.c b/main.c
> index 1db3241..12cb4c5 100644
> --- a/main.c
> +++ b/main.c
> @@ -47,12 +47,16 @@ static void
>  exec_self(int argc, char **argv)
>  {
>  	int i;
> -	const char *cmd = rpc_exec_lookup(argv[0]);
> -	char **args = calloc(argc + 1, sizeof(char *));
> +	const char *cmd;
> +	char **args;
>  
> -	if (!cmd || !args)
> +	cmd = rpc_exec_lookup(argv[0]);
> +	if (!cmd)
>  		return;
>  
> +	args = calloc(argc + 1, sizeof(char *));
> +	if (!args)
> +		return;
>  	for (i = 0; i < argc; i++)
>  		args[i] = argv[i];
>  
> 

-- 
ynezz

_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list