]> granicus.if.org Git - psmisc/commitdiff
killall: fix alloc on command
authorCraig Small <csmall@enc.com.au>
Thu, 25 Jun 2015 11:39:47 +0000 (21:39 +1000)
committerCraig Small <csmall@enc.com.au>
Thu, 25 Jun 2015 11:39:47 +0000 (21:39 +1000)
The command variable wasn't assigned before it was freed in the
loop. This change fixes that.

src/killall.c

index 90532ff5e447e7ce34234efc06046b2f2b09e5b1..617b38b9eab874904c911e8a7c07e5502adc62a1 100644 (file)
@@ -435,7 +435,7 @@ kill_all (int signal, int name_count, char **namelist, struct passwd *pwent)
     struct stat st;
     NAMEINFO *name_info = NULL;
     char *path, comm[COMM_LEN];
-    char *command;
+    char *command = NULL;
     pid_t *pid_table, *pid_killed;
     pid_t *pgids = NULL;
     int i, j, length, got_long, error;
@@ -503,8 +503,6 @@ kill_all (int signal, int name_count, char **namelist, struct passwd *pwent)
        if ( older_than   && process_age_sec && (process_age_sec < older_than ) )
            continue;
 
-        if (command)
-            free(command);
         got_long = 0;
         command = NULL;                /* make gcc happy */
         if (length == COMM_LEN - 1)
@@ -612,6 +610,10 @@ kill_all (int signal, int name_count, char **namelist, struct passwd *pwent)
        else if (errno != ESRCH || interactive)
            fprintf (stderr, "%s(%d): %s\n", got_long ? command :
                    comm, id, strerror (errno));
+        if (command) {
+            free(command);
+           command = NULL;
+       }
     }
     free(reglist);
     free(pgids);