diff options
author | Phil Sutter <phil@nwl.cc> | 2023-06-22 00:46:53 +0200 |
---|---|---|
committer | Phil Sutter <phil@nwl.cc> | 2023-07-04 13:03:09 +0200 |
commit | b30364a7a94eacf80c81022309006d37479f2ae2 (patch) | |
tree | 80e8e285db1ad7f7fef2b878c7c73fee7c55121d /src | |
parent | 01e4dbb7a180239cfce68f1af94db0732030344d (diff) |
main: Make 'buf' variable branch-local
It is used only to linearize non-option argv for passing to
nft_run_cmd_from_buffer(), reduce its scope. Allows to safely move the
free() call there, too.
Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -361,9 +361,9 @@ int main(int argc, char * const *argv) const struct option *options = get_options(); bool interactive = false, define = false; const char *optstring = get_optstring(); - char *buf = NULL, *filename = NULL; unsigned int output_flags = 0; unsigned int debug_mask; + char *filename = NULL; unsigned int len; int i, val, rc; @@ -514,6 +514,8 @@ int main(int argc, char * const *argv) nft_ctx_output_set_flags(nft, output_flags); if (optind != argc) { + char *buf; + for (len = 0, i = optind; i < argc; i++) len += strlen(argv[i]) + strlen(" "); @@ -529,6 +531,7 @@ int main(int argc, char * const *argv) strcat(buf, " "); } rc = !!nft_run_cmd_from_buffer(nft, buf); + free(buf); } else if (filename != NULL) { rc = !!nft_run_cmd_from_filename(nft, filename); } else if (interactive) { @@ -543,7 +546,6 @@ int main(int argc, char * const *argv) exit(EXIT_FAILURE); } - free(buf); nft_ctx_free(nft); return rc; |