From: Jesse Gross Date: Sat, 16 Jan 2010 00:24:53 +0000 (-0500) Subject: netdev-linux: Avoid potential issues with unset FD. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49a6a1636f849eba12fb444651ee818628426f0d;p=openvswitch netdev-linux: Avoid potential issues with unset FD. 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. --- diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 85ef62a3..f2a6a5d0 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -812,6 +812,7 @@ netdev_linux_open(struct netdev_dev *netdev_dev_, int ethertype, /* Allocate network device. */ netdev = xzalloc(sizeof *netdev); + netdev->fd = -1; netdev_init(&netdev->netdev, netdev_dev_); error = netdev_get_flags(&netdev->netdev, &flags); @@ -868,8 +869,6 @@ netdev_linux_open(struct netdev_dev *netdev_dev_, int ethertype, if (error) { goto error; } - } else { - netdev->fd = -1; } *netdevp = &netdev->netdev; @@ -886,7 +885,7 @@ netdev_linux_close(struct 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);