]> git.puffer.fish Git - matthieu/frr.git/commitdiff
vtysh: make clang-SA happy about reusing stdin
authorDavid Lamparter <equinox@opensourcerouting.org>
Wed, 16 Oct 2024 10:50:50 +0000 (12:50 +0200)
committerDavid Lamparter <equinox@opensourcerouting.org>
Wed, 16 Oct 2024 11:30:25 +0000 (13:30 +0200)
While the logic here is perfectly fine, clang-SA doesn't understand that
the fopen() and fclose() match up with each other.  Just use a separate
variable to make clang-SA happy.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
vtysh/vtysh.c

index b452618ce0d72a1f35e454e8a26246862b7f5573..5a54c60c6b1111789b2d672a0b5cc4f83b515571 100644 (file)
@@ -695,7 +695,7 @@ static char *trim(char *s)
 int vtysh_mark_file(const char *filename)
 {
        struct vty *vty;
-       FILE *confp = NULL;
+       FILE *confp = NULL, *closefp = NULL;
        int ret;
        vector vline;
        int tried = 0;
@@ -708,7 +708,7 @@ int vtysh_mark_file(const char *filename)
        if (strncmp("-", filename, 1) == 0)
                confp = stdin;
        else
-               confp = fopen(filename, "r");
+               confp = closefp = fopen(filename, "r");
 
        if (confp == NULL) {
                fprintf(stderr, "%% Can't open config file %s due to '%s'.\n",
@@ -848,9 +848,8 @@ int vtysh_mark_file(const char *filename)
        vty_close(vty);
        XFREE(MTYPE_VTYSH_CMD, vty_buf_copy);
 
-       if (confp != stdin)
-               fclose(confp);
-
+       if (closefp)
+               fclose(closefp);
        return 0;
 }