From: Daniel Stenberg Date: Fri, 19 Apr 2024 07:13:42 +0000 (+0200) Subject: ftp: fix socket leak on rare error X-Git-Tag: curl-8_8_0~187 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b2523fc4390b43fa249b0cd8edc335815f811531;p=thirdparty%2Fcurl.git 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 --- 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;