[Asterisk-code-review] tcptls.c: Don't close TCP client file descriptors more than once (asterisk[16])

Friendly Automation asteriskteam at digium.com
Thu Oct 8 04:01:42 CDT 2020


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/15024 )

Change subject: tcptls.c: Don't close TCP client file descriptors more than once
......................................................................

tcptls.c: Don't close TCP client file descriptors more than once

ASTERISK-28430 #close

Change-Id: Ib556b0a0c95cca939e956886214ec8d828d89606
---
M main/tcptls.c
1 file changed, 3 insertions(+), 9 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, approved
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, but someone else must approve
  Friendly Automation: Approved for Submit



diff --git a/main/tcptls.c b/main/tcptls.c
index 6a26cb8..45eb29b 100644
--- a/main/tcptls.c
+++ b/main/tcptls.c
@@ -608,13 +608,8 @@
 	return handle_tcptls_connection(tcptls_session);
 
 client_start_error:
-	if (desc) {
-		close(desc->accept_fd);
-		desc->accept_fd = -1;
-	}
 	ao2_ref(tcptls_session, -1);
 	return NULL;
-
 }
 
 struct ast_tcptls_session_instance *ast_tcptls_client_create(struct ast_tcptls_session_args *desc)
@@ -631,10 +626,6 @@
 	/* If we return early, there is no connection */
 	ast_sockaddr_setnull(&desc->old_address);
 
-	if (desc->accept_fd != -1) {
-		close(desc->accept_fd);
-	}
-
 	fd = desc->accept_fd = socket(ast_sockaddr_is_ipv6(&desc->remote_address) ?
 				      AF_INET6 : AF_INET, SOCK_STREAM, IPPROTO_TCP);
 	if (desc->accept_fd < 0) {
@@ -672,6 +663,9 @@
 		goto error;
 	}
 
+	/* From here on out, the iostream owns the accept_fd and it will take
+	 * care of closing it when the iostream is closed */
+
 	tcptls_session->parent = desc;
 	tcptls_session->parent->worker_fn = NULL;
 	ast_sockaddr_copy(&tcptls_session->remote_address,

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15024
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Ib556b0a0c95cca939e956886214ec8d828d89606
Gerrit-Change-Number: 15024
Gerrit-PatchSet: 2
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20201008/ef4e171f/attachment-0001.html>


More information about the asterisk-code-review mailing list