]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
main: Make 'buf' variable branch-local
authorPhil Sutter <phil@nwl.cc>
Wed, 21 Jun 2023 22:46:53 +0000 (00:46 +0200)
committerPhil Sutter <phil@nwl.cc>
Tue, 4 Jul 2023 11:03:09 +0000 (13:03 +0200)
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>
src/main.c

index cb20850b71c5ba927b997d838e2dfc34778085a8..a1592c1823f496f53a8e537889493f94668288a4 100644 (file)
@@ -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;