Commit f56f15cc authored by Ben Walker's avatar Ben Walker Committed by Tomasz Zawadzki
Browse files

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: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/475311


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
parent f1d0c5ab
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -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) {
	/* 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);

	free(sock);
	}

	return rc;
	return 0;
}

static ssize_t