From 2f1cd867f3dedb1213e700eb042ba8c62a2afe9f Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Wed, 24 Feb 2021 23:28:54 +0800 Subject: [PATCH] sock/uring: Refactor the code in uring_sock_close Use the same style compared the code in posix_sock_close. Thus if we cannot close sock->fd, i.e., we leak the fd, but we can still free the memory related with uring sock. Signed-off-by: Ziye Yang Change-Id: Id2f0e8a2c7065f100c2b009e76a49b528fd221b6 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6539 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Shuhei Matsumoto Reviewed-by: Aleksey Marchuk --- module/sock/uring/uring.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/module/sock/uring/uring.c b/module/sock/uring/uring.c index f80a709b8..e050ca954 100644 --- a/module/sock/uring/uring.c +++ b/module/sock/uring/uring.c @@ -585,19 +585,20 @@ static int uring_sock_close(struct spdk_sock *_sock) { struct spdk_uring_sock *sock = __uring_sock(_sock); - int rc; assert(TAILQ_EMPTY(&_sock->pending_reqs)); assert(sock->group == NULL); + /* If the socket fails to close, the best choice is to + * leak the fd but continue to free the rest of the sock + * memory. */ + close(sock->fd); + spdk_pipe_destroy(sock->recv_pipe); free(sock->recv_buf); - rc = close(sock->fd); - if (rc == 0) { - free(sock); - } + free(sock); - return rc; + return 0; } static ssize_t