Never close the file descriptor if it is 0, since it is never a
valid FD in this context. Also initialize the FD to -1 so that
it is never set to a valid but incorrect value.
/* Allocate network device. */
netdev = xzalloc(sizeof *netdev);
+ netdev->fd = -1;
netdev_init(&netdev->netdev, netdev_dev_);
error = netdev_get_flags(&netdev->netdev, &flags);
if (error) {
goto error;
}
- } else {
- netdev->fd = -1;
}
*netdevp = &netdev->netdev;
{
struct netdev_linux *netdev = netdev_linux_cast(netdev_);
- if (netdev->fd >= 0 && strcmp(netdev_get_type(netdev_), "tap")) {
+ if (netdev->fd > 0 && strcmp(netdev_get_type(netdev_), "tap")) {
close(netdev->fd);
}
free(netdev);