* [Qemu-devel] [PATCH] tap: fix memory leak on failure in net_init_tap()
@ 2017-01-10 19:21 Peter Maydell
2017-01-11 3:08 ` Jason Wang
0 siblings, 1 reply; 2+ messages in thread
From: Peter Maydell @ 2017-01-10 19:21 UTC (permalink / raw)
To: qemu-devel; +Cc: patches, Paolo Bonzini, Jason Wang
Commit 091a6b2ac fixed most of the memory leaks in failure
paths in net_init_tap() reported by Coverity (CID 1356216),
but missed one. Fix it by deferring the allocation of
fds and vhost_fds until after the error check.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
net/tap.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/net/tap.c b/net/tap.c
index b6896a7..6248e85 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -788,8 +788,8 @@ int net_init_tap(const Netdev *netdev, const char *name,
return -1;
}
} else if (tap->has_fds) {
- char **fds = g_new0(char *, MAX_TAP_QUEUES);
- char **vhost_fds = g_new0(char *, MAX_TAP_QUEUES);
+ char **fds;
+ char **vhost_fds;
int nfds, nvhosts;
if (tap->has_ifname || tap->has_script || tap->has_downscript ||
@@ -801,6 +801,9 @@ int net_init_tap(const Netdev *netdev, const char *name,
return -1;
}
+ fds = g_new0(char *, MAX_TAP_QUEUES);
+ vhost_fds = g_new0(char *, MAX_TAP_QUEUES);
+
nfds = get_fds(tap->fds, fds, MAX_TAP_QUEUES);
if (tap->has_vhostfds) {
nvhosts = get_fds(tap->vhostfds, vhost_fds, MAX_TAP_QUEUES);
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] tap: fix memory leak on failure in net_init_tap()
2017-01-10 19:21 [Qemu-devel] [PATCH] tap: fix memory leak on failure in net_init_tap() Peter Maydell
@ 2017-01-11 3:08 ` Jason Wang
0 siblings, 0 replies; 2+ messages in thread
From: Jason Wang @ 2017-01-11 3:08 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: patches, Paolo Bonzini
On 2017年01月11日 03:21, Peter Maydell wrote:
> Commit 091a6b2ac fixed most of the memory leaks in failure
> paths in net_init_tap() reported by Coverity (CID 1356216),
> but missed one. Fix it by deferring the allocation of
> fds and vhost_fds until after the error check.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> net/tap.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/net/tap.c b/net/tap.c
> index b6896a7..6248e85 100644
> --- a/net/tap.c
> +++ b/net/tap.c
> @@ -788,8 +788,8 @@ int net_init_tap(const Netdev *netdev, const char *name,
> return -1;
> }
> } else if (tap->has_fds) {
> - char **fds = g_new0(char *, MAX_TAP_QUEUES);
> - char **vhost_fds = g_new0(char *, MAX_TAP_QUEUES);
> + char **fds;
> + char **vhost_fds;
> int nfds, nvhosts;
>
> if (tap->has_ifname || tap->has_script || tap->has_downscript ||
> @@ -801,6 +801,9 @@ int net_init_tap(const Netdev *netdev, const char *name,
> return -1;
> }
>
> + fds = g_new0(char *, MAX_TAP_QUEUES);
> + vhost_fds = g_new0(char *, MAX_TAP_QUEUES);
> +
> nfds = get_fds(tap->fds, fds, MAX_TAP_QUEUES);
> if (tap->has_vhostfds) {
> nvhosts = get_fds(tap->vhostfds, vhost_fds, MAX_TAP_QUEUES);
Applied to -net.
Thanks
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-01-11 3:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-10 19:21 [Qemu-devel] [PATCH] tap: fix memory leak on failure in net_init_tap() Peter Maydell
2017-01-11 3:08 ` Jason Wang
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.