From f458b580e1b1f987f941f823023108c563403bf7 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Tue, 31 Jul 2007 12:45:41 +0000 Subject: [PATCH] Rework bnet_server exit code git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@5270 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/lib/bnet_server.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/bacula/src/lib/bnet_server.c b/bacula/src/lib/bnet_server.c index 76d58a2162..d6bac6de05 100644 --- a/bacula/src/lib/bnet_server.c +++ b/bacula/src/lib/bnet_server.c @@ -96,7 +96,8 @@ bnet_thread_server(dlist *addrs, int max_clients, workq_t *client_wq, Dmsg1(100, "Addresses %s\n", build_addresses_str(addrs, allbuf, sizeof(allbuf))); foreach_dlist(p, addrs) { - fd_ptr = (s_sockfd *)malloc(sizeof(s_sockfd)); + /* Allocate on stack from -- no need to free */ + fd_ptr = (s_sockfd *)alloca(sizeof(s_sockfd)); fd_ptr->port = p->get_port_net_order(); /* * Open a TCP socket @@ -162,10 +163,6 @@ bnet_thread_server(dlist *addrs, int max_clients, workq_t *client_wq, if (errno == EINTR) { continue; } - /* Error, get out */ - foreach_dlist(fd_ptr, &sockfds) { - close(fd_ptr->fd); - } Emsg1(M_FATAL, 0, _("Error in select: %s\n"), be.bstrerror()); break; } @@ -227,6 +224,12 @@ bnet_thread_server(dlist *addrs, int max_clients, workq_t *client_wq, } } + /* Cleanup open files and pointers to them */ + while ((fd_ptr = (s_sockfd *)sockfds.first())) { + close(fd_ptr->fd); + sockfds.remove(fd_ptr); /* don't free() item it is on stack */ + } + /* Stop work queue thread */ if ((stat = workq_destroy(client_wq)) != 0) { berrno be; -- 2.39.5