tap: fix a memory leak

Close fd before returning.

Buglink: https://bugs.launchpad.net/qemu/+bug/1904486

Signed-off-by: yuanjungong <ruc_gongyuanjun@163.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Jason Wang <jasowang@redhat.com>
This commit is contained in:
yuanjungong 2020-11-19 17:25:32 +08:00 committed by Jason Wang
parent d2abc563e4
commit f012bec890

View File

@ -817,6 +817,7 @@ int net_init_tap(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;
}
@ -831,6 +832,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
vhostfdname, vnet_hdr, fd, &err);
if (err) {
error_propagate(errp, err);
close(fd);
return -1;
}
} else if (tap->has_fds) {