|
| From: | Stefano Garzarella |
| Subject: | Re: [PATCH 1/1] net/socket.c: Fix memory leak |
| Date: | Thu, 10 Dec 2020 09:51:48 +0100 |
On Wed, Dec 09, 2020 at 08:00:13PM +0800, ruc_gongyuanjun@163.com wrote:
From: yuanjungong <ruc_gongyuanjun@163.com>
close fd opened by monitor_fd_param() before returning.
Signed-off-by: yuanjungong <ruc_gongyuanjun@163.com>
---
net/socket.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/socket.c b/net/socket.c
index 15b410e..2f720a7 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -735,12 +735,15 @@ int net_init_socket(const Netdev *netdev, const char
*name,
if (ret < 0) {
error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d",
name, fd);
+ close(fd);
return -1;
}
if (!net_socket_fd_init(peer, "socket", name, fd, 1, sock->mcast,
errp)) {
+ close(fd);
net_socket_fd_init() closes the fd in the error path, so this close should be avoided.
return -1;
}
+ close(fd);
I don't know the code, but is it right to close the file descriptor in the success path?
Thanks, Stefano
return 0;
}
--
2.17.1
| [Prev in Thread] | Current Thread | [Next in Thread] |