]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ftp: fix socket leak on rare error
authorDaniel Stenberg <daniel@haxx.se>
Fri, 19 Apr 2024 07:13:42 +0000 (09:13 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 19 Apr 2024 09:10:50 +0000 (11:10 +0200)
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

index 648cab3f6e0c42fd1c2c5440ef36c2ce3aa01b98..9e10704f2c9aae09e0176ff71b169fe8000e7501 100644 (file)
--- 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;