]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
ulogd: fix config file fd leak
authorCorubba Smith <corubba@gmx.de>
Sat, 8 Mar 2025 22:32:29 +0000 (23:32 +0100)
committerFlorian Westphal <fw@strlen.de>
Wed, 12 Mar 2025 08:10:01 +0000 (09:10 +0100)
Consistently use the return jump to close the config file descriptor if
opened, to prevent it from leaking.

Signed-off-by: Corubba Smith <corubba@gmx.de>
Signed-off-by: Florian Westphal <fw@strlen.de>
src/conffile.c

index 66769decc93c2d3b9663ad1b2f4c0cbb25fba546..5b7f8341f111acfbd837437bc5af5eabb336f4c6 100644 (file)
@@ -143,7 +143,8 @@ int config_parse_file(const char *section, struct config_keyset *kset)
                /* if line was fetch completely, string ends with '\n' */
                if (! strchr(line, '\n')) {
                        ulogd_log(ULOGD_ERROR, "line %d too long.\n", linenum);
-                       return -ERRTOOLONG;
+                       err = -ERRTOOLONG;
+                       goto cpf_error;
                }
 
                if (!(wordend = get_word(line, " \t\n\r[]", (char *) wordbuf)))
@@ -156,8 +157,8 @@ int config_parse_file(const char *section, struct config_keyset *kset)
        }
 
        if (!found) {
-               fclose(cfile);
-               return -ERRSECTION;
+               err = -ERRSECTION;
+               goto cpf_error;
        }
 
        /* Parse this section until next section */
@@ -175,7 +176,8 @@ int config_parse_file(const char *section, struct config_keyset *kset)
                /* if line was fetch completely, string ends with '\n' */
                if (! strchr(line, '\n')) {
                        ulogd_log(ULOGD_ERROR, "line %d too long.\n", linenum);
-                       return -ERRTOOLONG;
+                       err = -ERRTOOLONG;
+                       goto cpf_error;
                }
 
                if (!(wordend = get_word(line, " =\t\n\r", (char *) &wordbuf)))