X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/78211e93e9a370556c7c44b204dfac7b47766b43..eee44c467bf31f198c73a51cab2f7e9d5a2ad47c:/sbr/arglist.c diff --git a/sbr/arglist.c b/sbr/arglist.c index 20bf84c7..8749a4b9 100644 --- a/sbr/arglist.c +++ b/sbr/arglist.c @@ -25,10 +25,10 @@ * * - If there are no spaces or shell metacharacters in "command", then * take it as-is. - * - If there are spaces in command, space-split command string and - * append an argument list to it. + * - If there are spaces in command, space-split command string. * - If we have shell metacharacters, run the command using - * /bin/sh -c 'command "${@}"'. + * /bin/sh -c 'command "$@"'. In this case, any additional arguments + * appended to the arglist will be expanded by "$@". * * In all cases additional arguments can be added to the argv[] array. */ @@ -90,6 +90,7 @@ argsplit(char *command, char **file, int *argp) *file = getcpy(split[0]); if (argp) *argp = i; + free(p); return argvarray; } @@ -122,3 +123,22 @@ argsplit(char *command, char **file, int *argp) return argvarray; } + +/* + * Free our argument array + */ + +void +arglist_free(char *command, char **argvarray) +{ + int i; + + if (command != NULL) + free(command); + + if (argvarray != NULL) { + for (i = 0; argvarray[i] != NULL; i++) + free(argvarray[i]); + free(argvarray); + } +}