On FreeBSD, virNetDevTapCreateInBridgePort() might leak a tap(4) device. Specifically, we're creating a tap(4) device with virNetDevTapCreate() early in the function. Then we are performing various operations, e.g. virNetDevSetMAC() and virNetDevTapAttachBridge(), and on errors jump to the 'error' cleanup label where we close the tap device. As tap(4) devices configured by libvirt on FreeBSD do not destroy themselves on closing, they leak on errors in this function. So make sure to add device removal to the error handling of this function. Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com> --- src/util/virnetdevtap.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index aa0907dd0c..6c228ff086 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -695,6 +695,16 @@ int virNetDevTapCreateInBridgePort(const char *brname, for (i = 0; i < tapfdSize && tapfd[i] >= 0; i++) VIR_FORCE_CLOSE(tapfd[i]); +#if defined(VIR_NETDEV_TAP_REQUIRE_MANUAL_CLEANUP) + if (!(flags & VIR_NETDEV_TAP_CREATE_ALLOW_EXISTING)) { + virErrorPtr err; + + virErrorPreserveLast(&err); + ignore_value(virNetDevTapDelete(*ifname, tunpath)); + virErrorRestore(&err); + } +#endif /* VIR_NETDEV_TAP_REQUIRE_MANUAL_CLEANUP */ + return -1; } -- 2.55.0