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 <benjamin.walker@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/475311 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
f1d0c5aba0
commit
f56f15cc28
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user