瀏覽代碼

Fix a file descriptor leak in TapInterfaceDesc::interface_mtu.

whitequark 7 年之前
父節點
當前提交
974bad1adf
共有 1 個文件被更改,包括 5 次插入1 次删除
  1. 5 1
      src/phy/sys/tap_interface.rs

+ 5 - 1
src/phy/sys/tap_interface.rs

@@ -37,7 +37,11 @@ impl TapInterfaceDesc {
             lower
         };
 
-        ifreq_ioctl(lower, &mut self.ifreq, imp::SIOCGIFMTU).map(|mtu| mtu as usize)
+        let mtu = ifreq_ioctl(lower, &mut self.ifreq, imp::SIOCGIFMTU).map(|mtu| mtu as usize);
+
+        unsafe { libc::close(lower); }
+
+        mtu
     }
 
     fn wait(&mut self, ms: u32) -> io::Result<bool> {