aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorGonglei <arei.gonglei@huawei.com>2014-11-02 13:37:17 +0800
committerMichael Tokarev <mjt@tls.msk.ru>2014-11-02 10:05:35 +0300
commit84f8f3dace8c6e88b1afa828f9abe1e9a57fac1a (patch)
treea0c81e5c098c38ab06b882128f3154e6b1ce4711 /net
parentd0caa3eb539de01043354440ce0a10b1f546cf06 (diff)
downloadqemu-84f8f3dace8c6e88b1afa828f9abe1e9a57fac1a.zip
qemu-84f8f3dace8c6e88b1afa828f9abe1e9a57fac1a.tar.gz
qemu-84f8f3dace8c6e88b1afa828f9abe1e9a57fac1a.tar.bz2
tap: fix possible fd leak in net_init_tap
In hotplugging scenario, taking those true branch, the file handler do not be closed. Let's close them before return. Signed-off-by: Gonglei <arei.gonglei@huawei.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Diffstat (limited to 'net')
-rw-r--r--net/tap.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/net/tap.c b/net/tap.c
index 7bcd4c7..bde6b58 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -796,6 +796,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
if (net_init_tap_one(tap, peer, "bridge", name, ifname,
script, downscript, vhostfdname,
vnet_hdr, fd)) {
+ close(fd);
return -1;
}
} else {
@@ -823,6 +824,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
if (queues > 1 && i == 0 && !tap->has_ifname) {
if (tap_fd_get_ifname(fd, ifname)) {
error_report("Fail to get ifname");
+ close(fd);
return -1;
}
}
@@ -831,6 +833,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
i >= 1 ? "no" : script,
i >= 1 ? "no" : downscript,
vhostfdname, vnet_hdr, fd)) {
+ close(fd);
return -1;
}
}