From patchwork Wed May 27 08:37:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Baum X-Patchwork-Id: 70601 X-Patchwork-Delegate: rasland@nvidia.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E9A49A04A4; Wed, 27 May 2020 10:39:22 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 247C01D8EB; Wed, 27 May 2020 10:38:59 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 309C41D60E for ; Wed, 27 May 2020 10:38:57 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE2 (envelope-from matan@mellanox.com) with ESMTPS (AES256-SHA encrypted); 27 May 2020 11:38:55 +0300 Received: from pegasus07.mtr.labs.mlnx (pegasus07.mtr.labs.mlnx [10.210.16.112]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 04R8cgsv005678; Wed, 27 May 2020 11:38:55 +0300 From: Michael Baum To: dev@dpdk.org Cc: matan@mellanox.com, viacheslavo@mellanox.com, stable@dpdk.org Date: Wed, 27 May 2020 08:37:55 +0000 Message-Id: <1590568677-11662-4-git-send-email-michaelba@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1590568677-11662-1-git-send-email-michaelba@mellanox.com> References: <1590568677-11662-1-git-send-email-michaelba@mellanox.com> Subject: [dpdk-dev] [PATCH 4/6] net/mlx5: fix socket handle closing X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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@dpdk.org Signed-off-by: Michael Baum Acked-by: Matan Azrad --- 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);