summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2023-06-22 00:46:53 +0200
committerPhil Sutter <phil@nwl.cc>2023-07-04 13:03:09 +0200
commitb30364a7a94eacf80c81022309006d37479f2ae2 (patch)
tree80e8e285db1ad7f7fef2b878c7c73fee7c55121d /src/main.c
parent01e4dbb7a180239cfce68f1af94db0732030344d (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/main.c')
-rw-r--r--src/main.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index cb20850b..a1592c18 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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;