main: exec_self: make clang analyzer happy
authorYousong Zhou <yszhou4tech@gmail.com>
Mon, 21 Oct 2019 12:59:24 +0000 (12:59 +0000)
committerJo-Philipp Wich <jo@mein.io>
Tue, 29 Oct 2019 08:26:24 +0000 (09:26 +0100)
Prevent a theoretical leak of the args memory when the executable path
cannot be found.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
[fix whitespace, commit description]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
main.c

diff --git a/main.c b/main.c
index 1db3241958f0d61ba01c59a5f6710b7d6839e58b..9a177cfb7e313dee89ee6012fbc15ede89d696d0 100644 (file)
--- a/main.c
+++ b/main.c
@@ -47,10 +47,15 @@ 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++)