aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2017-01-10 19:21:54 +0000
committerJason Wang <jasowang@redhat.com>2017-01-20 10:58:26 +0800
commitfac7d7b1cdb21f921d7ac396365f5e920ef03096 (patch)
treedd3877fdffab1aa851a402520491ce3eb910c50e /net
parenta023b7ac6262106e9a7d248bb61ec928fbf94896 (diff)
downloadqemu-fac7d7b1cdb21f921d7ac396365f5e920ef03096.zip
qemu-fac7d7b1cdb21f921d7ac396365f5e920ef03096.tar.gz
qemu-fac7d7b1cdb21f921d7ac396365f5e920ef03096.tar.bz2
tap: fix memory leak on failure in net_init_tap()
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> Signed-off-by: Jason Wang <jasowang@redhat.com>
Diffstat (limited to 'net')
-rw-r--r--net/tap.c7
1 files 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);