[PATCH] tools/lib/subcmd: Move va_end before exit

Luo Yifan posted 1 patch 1 week, 5 days ago
tools/lib/subcmd/subcmd-util.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] tools/lib/subcmd: Move va_end before exit
Posted by Luo Yifan 1 week, 5 days ago
This patch makes a minor adjustment by moving the va_end call before
exit. Since the exit() function terminates the program, any code
after exit(128) (i.e., va_end(params)) is unreachable and thus not
executed. Placing va_end before exit ensures that the va_list is
properly cleaned up.

Signed-off-by: Luo Yifan <luoyifan@cmss.chinamobile.com>
---
 tools/lib/subcmd/subcmd-util.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/subcmd/subcmd-util.h b/tools/lib/subcmd/subcmd-util.h
index dfac76e35..c742b0881 100644
--- a/tools/lib/subcmd/subcmd-util.h
+++ b/tools/lib/subcmd/subcmd-util.h
@@ -20,8 +20,8 @@ static __noreturn inline void die(const char *err, ...)
 
 	va_start(params, err);
 	report(" Fatal: ", err, params);
-	exit(128);
 	va_end(params);
+	exit(128);
 }
 
 #define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
-- 
2.27.0
Re: [PATCH] tools/lib/subcmd: Move va_end before exit
Posted by Arnaldo Carvalho de Melo 1 week, 5 days ago
On Mon, Nov 11, 2024 at 05:17:01PM +0800, Luo Yifan wrote:
> This patch makes a minor adjustment by moving the va_end call before
> exit. Since the exit() function terminates the program, any code
> after exit(128) (i.e., va_end(params)) is unreachable and thus not
> executed. Placing va_end before exit ensures that the va_list is
> properly cleaned up.

Thanks, applied to perf-tools-next,

- Arnaldo
 
> Signed-off-by: Luo Yifan <luoyifan@cmss.chinamobile.com>
> ---
>  tools/lib/subcmd/subcmd-util.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/lib/subcmd/subcmd-util.h b/tools/lib/subcmd/subcmd-util.h
> index dfac76e35..c742b0881 100644
> --- a/tools/lib/subcmd/subcmd-util.h
> +++ b/tools/lib/subcmd/subcmd-util.h
> @@ -20,8 +20,8 @@ static __noreturn inline void die(const char *err, ...)
>  
>  	va_start(params, err);
>  	report(" Fatal: ", err, params);
> -	exit(128);
>  	va_end(params);
> +	exit(128);
>  }
>  
>  #define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
> -- 
> 2.27.0
> 
>