From 03340fe595288ea8f62d3d0d0f7e06f76af862cf Mon Sep 17 00:00:00 2001 From: "Bruce A. Mah" Date: Wed, 21 Sep 2016 11:25:18 -0700 Subject: [PATCH] Prevent a double-close on the server side in some cases. Alternate solution to a problem pointed out by @g-coder in pull request #429. --- src/iperf_server_api.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/iperf_server_api.c b/src/iperf_server_api.c index 227ec78..65661d7 100644 --- a/src/iperf_server_api.c +++ b/src/iperf_server_api.c @@ -1,5 +1,5 @@ /* - * iperf, Copyright (c) 2014, 2015, The Regents of the University of + * iperf, Copyright (c) 2014, 2015, 2016, The Regents of the University of * California, through Lawrence Berkeley National Laboratory (subject * to receipt of any required approvals from the U.S. Dept. of * Energy). All rights reserved. @@ -410,8 +410,12 @@ static void cleanup_server(struct iperf_test *test) { /* Close open test sockets */ - close(test->ctrl_sck); - close(test->listener); + if (test->ctrl_sck) { + close(test->ctrl_sck); + } + if (test->listener) { + close(test->listener); + } /* Cancel any remaining timers. */ if (test->stats_timer != NULL) { @@ -545,6 +549,7 @@ iperf_run_server(struct iperf_test *test) if (test->no_delay || test->settings->mss || test->settings->socket_bufsize) { FD_CLR(test->listener, &test->read_set); close(test->listener); + test->listener = 0; if ((s = netannounce(test->settings->domain, Ptcp, test->bind_address, test->server_port)) < 0) { cleanup_server(test); i_errno = IELISTEN;