* [PATCH 1/1] net/socket.c: Fix memory leak
@ 2020-12-09 12:00 ruc_gongyuanjun
2020-12-10 8:51 ` Stefano Garzarella
0 siblings, 1 reply; 2+ messages in thread
From: ruc_gongyuanjun @ 2020-12-09 12:00 UTC (permalink / raw)
To: Jason Wang, qemu-devel; +Cc: yuanjungong
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);
return -1;
}
+ close(fd);
return 0;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 1/1] net/socket.c: Fix memory leak
2020-12-09 12:00 [PATCH 1/1] net/socket.c: Fix memory leak ruc_gongyuanjun
@ 2020-12-10 8:51 ` Stefano Garzarella
0 siblings, 0 replies; 2+ messages in thread
From: Stefano Garzarella @ 2020-12-10 8:51 UTC (permalink / raw)
To: ruc_gongyuanjun; +Cc: Jason Wang, qemu-devel
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
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-12-10 8:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-09 12:00 [PATCH 1/1] net/socket.c: Fix memory leak ruc_gongyuanjun
2020-12-10 8:51 ` Stefano Garzarella
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.