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>
This commit is contained in:
Gonglei 2014-11-02 13:37:17 +08:00 committed by Michael Tokarev
parent d0caa3eb53
commit 84f8f3dace
1 changed files with 3 additions and 0 deletions

View File

@ -796,6 +796,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
if (net_init_tap_one(tap, peer, "bridge", name, ifname, if (net_init_tap_one(tap, peer, "bridge", name, ifname,
script, downscript, vhostfdname, script, downscript, vhostfdname,
vnet_hdr, fd)) { vnet_hdr, fd)) {
close(fd);
return -1; return -1;
} }
} else { } else {
@ -823,6 +824,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
if (queues > 1 && i == 0 && !tap->has_ifname) { if (queues > 1 && i == 0 && !tap->has_ifname) {
if (tap_fd_get_ifname(fd, ifname)) { if (tap_fd_get_ifname(fd, ifname)) {
error_report("Fail to get ifname"); error_report("Fail to get ifname");
close(fd);
return -1; return -1;
} }
} }
@ -831,6 +833,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
i >= 1 ? "no" : script, i >= 1 ? "no" : script,
i >= 1 ? "no" : downscript, i >= 1 ? "no" : downscript,
vhostfdname, vnet_hdr, fd)) { vhostfdname, vnet_hdr, fd)) {
close(fd);
return -1; return -1;
} }
} }