From b2523fc4390b43fa249b0cd8edc335815f811531 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 19 Apr 2024 09:13:42 +0200 Subject: [PATCH] ftp: fix socket leak on rare error In the function AcceptServerConnect() the newly created socket would leak if Curl_conn_tcp_accepted_set() returns error. Which basically should never happen. Spotted by CodeSonar. Closes #13417 --- lib/ftp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/ftp.c b/lib/ftp.c index 648cab3f6e..9e10704f2c 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -388,8 +388,10 @@ static CURLcode AcceptServerConnect(struct Curl_easy *data) (void)curlx_nonblock(s, TRUE); /* enable non-blocking */ /* Replace any filter on SECONDARY with one listening on this socket */ result = Curl_conn_tcp_accepted_set(data, conn, SECONDARYSOCKET, &s); - if(result) + if(result) { + sclose(s); return result; + } if(data->set.fsockopt) { int error = 0; -- 2.47.3