summaryrefslogtreecommitdiff
path: root/lib/netdev-linux.c
diff options
context:
space:
mode:
authorJesse Gross <jesse@nicira.com>2010-01-15 19:24:53 -0500
committerJesse Gross <jesse@nicira.com>2010-01-18 18:23:14 -0500
commit49a6a1636f849eba12fb444651ee818628426f0d (patch)
tree5014c812929c030ce8c8b4c6fd0e7bbf1c1d9ed8 /lib/netdev-linux.c
parent83497018966c159498d9f26e2539f3edb1b410a1 (diff)
downloadopenvswitch-49a6a1636f849eba12fb444651ee818628426f0d.tar.gz
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.
Diffstat (limited to 'lib/netdev-linux.c')
-rw-r--r--lib/netdev-linux.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index 85ef62a39..f2a6a5d04 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);