BUG/MEDIUM: server: resolve state file handle leak on reload
authorIlya Shipitsin <chipitsine@gmail.com>
Wed, 15 Jul 2020 21:02:40 +0000 (02:02 +0500)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 17 Jul 2020 08:29:29 +0000 (10:29 +0200)
During reload, server state file is read and file handle is not released
this was indepently reported in #738 and #660.

partially resolves #660. This should be backported to 2.2 and 2.1.

(cherry picked from commit dc6e8a9a7b19052b8fd8ab7f9a84a4a95b4a6d5b)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit d74774bca53a2f4c30995d01eeb028dde313fc29)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/server.c

index 408458f..dd7b9bf 100644 (file)
@@ -3515,6 +3515,11 @@ void apply_server_state(void)
        }
  out_load_server_state_in_tree:
 
+       if (f) {
+               fclose(f);
+               f = NULL;
+       }
+
        /* parse all proxies and load states form tree (global file) or from local file */
        for (curproxy = proxies_list; curproxy != NULL; curproxy = curproxy->next) {
                /* servers are only in backends */
@@ -3694,9 +3699,11 @@ void apply_server_state(void)
                                /* now we can proceed with server's state update */
                                srv_update_state(srv, version, srv_params);
                        }
+
+                       fileclose:
+                               fclose(f);
+
                }
-fileclose:
-               fclose(f);
        }
 
        /* now free memory allocated for the tree */