[dpdk-dev] [PATCH 4/6] net/mlx5: fix socket handle closing

Michael Baum michaelba at mellanox.com
Wed May 27 10:37:55 CEST 2020


The mlx5_pmd_socket_handle function calls the accept function that
returns the socket descriptor into the conn_sock variable. The socket
descriptor value can be 0 (according to accept API) or positive and so
immediately after calling the function it checks whether conn_sock < 0.
Later in the function when other things fail it jumps to the error label
and release previously allocated resources (such as socket or file).

During the resource release, it checks whether the variable conn_sock
containing the socket descriptor is positive and if it is, it releases
it. However, in this check it misses the case where conn_sock == 0, in
this case the socket will not be released and there will be a Resource
leak.

Extend the close condition for 0 value too.

Fixes: e6cdc54cc0ef ("net/mlx5: add socket server for external tools")
Cc: stable at dpdk.org

Signed-off-by: Michael Baum <michaelba at mellanox.com>
Acked-by: Matan Azrad <matan at mellanox.com>
---
 drivers/net/mlx5/mlx5_socket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/mlx5/mlx5_socket.c b/drivers/net/mlx5/mlx5_socket.c
index f473795..08af905 100644
--- a/drivers/net/mlx5/mlx5_socket.c
+++ b/drivers/net/mlx5/mlx5_socket.c
@@ -109,7 +109,7 @@
 		DRV_LOG(WARNING, "failed to send response %s",
 			strerror(errno));
 error:
-	if (conn_sock > 0)
+	if (conn_sock >= 0)
 		close(conn_sock);
 	if (file)
 		fclose(file);
-- 
1.8.3.1



More information about the dev mailing list