diff --git a/src/fd.c b/src/fd.c index c197557be..8dab4977a 100644 --- a/src/fd.c +++ b/src/fd.c @@ -270,10 +270,16 @@ int init_pollers() int p; struct poller *bp; - if ((fd_cache = calloc(1, sizeof(uint32_t) * global.maxsock)) == NULL) + if ((fdtab = calloc(global.maxsock, sizeof(struct fdtab))) == NULL) + goto fail_tab; + + if ((fdinfo = calloc(global.maxsock, sizeof(struct fdinfo))) == NULL) + goto fail_info; + + if ((fd_cache = calloc(global.maxsock, sizeof(*fd_cache))) == NULL) goto fail_cache; - if ((fd_updt = calloc(1, sizeof(uint32_t) * global.maxsock)) == NULL) + if ((fd_updt = calloc(global.maxsock, sizeof(*fd_updt))) == NULL) goto fail_updt; do { @@ -295,6 +301,10 @@ int init_pollers() fail_updt: free(fd_cache); fail_cache: + free(fdinfo); + fail_info: + free(fdtab); + fail_tab: return 0; } @@ -312,11 +322,10 @@ void deinit_pollers() { if (bp && bp->pref) bp->term(bp); } - - free(fd_updt); - free(fd_cache); - fd_updt = NULL; - fd_cache = NULL; + free(fd_updt); fd_updt = NULL; + free(fd_cache); fd_cache = NULL; + free(fdinfo); fdinfo = NULL; + free(fdtab); fdtab = NULL; } /* diff --git a/src/haproxy.c b/src/haproxy.c index 488a07617..fc99225c0 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -1718,9 +1718,6 @@ static void init(int argc, char **argv) exit(1); } - - fdinfo = calloc(1, sizeof(struct fdinfo) * (global.maxsock)); - fdtab = calloc(1, sizeof(struct fdtab) * (global.maxsock)); /* * Note: we could register external pollers here. * Built-in pollers have been registered before main(). @@ -2118,8 +2115,6 @@ void deinit(void) free(global.pidfile); global.pidfile = NULL; free(global.node); global.node = NULL; free(global.desc); global.desc = NULL; - free(fdinfo); fdinfo = NULL; - free(fdtab); fdtab = NULL; free(oldpids); oldpids = NULL; free(global_listener_queue_task); global_listener_queue_task = NULL;