From f56f15cc28769e138a831c0c4e9f628e13112c8d Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Wed, 20 Nov 2019 13:29:26 -0700 Subject: [PATCH] sock/posix: Release socket memory even if close() fails Close can't fail. And if it did, we still want to release the sock memory. Change-Id: I0e4f4d23d49f32132f4526fef8587823ace0a774 Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/475311 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- module/sock/posix/posix.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/module/sock/posix/posix.c b/module/sock/posix/posix.c index 1e3c49449..c4ce544cb 100644 --- a/module/sock/posix/posix.c +++ b/module/sock/posix/posix.c @@ -422,14 +422,15 @@ static int spdk_posix_sock_close(struct spdk_sock *_sock) { struct spdk_posix_sock *sock = __posix_sock(_sock); - int rc; - rc = close(sock->fd); - if (rc == 0) { - free(sock); - } + /* 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); - return rc; + free(sock); + + return 0; } static ssize_t