commit fc85dc819da6dcc83bc6da0bb01e725256d2977e
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Fri Sep 22 14:18:14 2023 +0200
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Fri Sep 22 14:18:14 2023 +0200

    xargs: Free argument before substitution
    
    strnsubst() allocates a new array always, indepently of
    the number of occurences of the replace string.

diff --git a/xargs.c b/xargs.c
index 30b09ab..0d37ec8 100644
--- a/xargs.c
+++ b/xargs.c
@@ -266,9 +266,11 @@ main(int argc, char *argv[])
                                argsz += arglen + 1;
                        } else {
                                for (j = 1; j < i; j++) {
+                                       char *p = cmd[j];
                                        argsz -= strlen(cmd[j]);
                                        strnsubst(&cmd[j], replstr, arg, 255);
                                        argsz += strlen(cmd[j]);
+                                       free(p);
                                }
                        }
 

Reply via email to