[patch 6/9] Fix qemudEnableIpForwarding()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Don't leak an fd if we fail to write to /proc/sys/net/ipv4/ip_forward

Also, fix indentation

Signed-off-by: Mark McLoughlin <markmc@xxxxxxxxxx>

Index: libvirt/qemud/qemud.c
===================================================================
--- libvirt.orig/qemud/qemud.c
+++ libvirt/qemud/qemud.c
@@ -982,15 +982,17 @@ qemudEnableIpForwarding(void)
 {
 #define PROC_IP_FORWARD "/proc/sys/net/ipv4/ip_forward"
 
-  int fd;
+    int fd, ret;
 
-  if ((fd = open(PROC_IP_FORWARD, O_WRONLY|O_TRUNC)) == -1 ||
-      write(fd, "1\n", 2) < 0)
-      return 0;
+    if ((fd = open(PROC_IP_FORWARD, O_WRONLY|O_TRUNC)) == -1)
+        return 0;
+
+    if (write(fd, "1\n", 2) < 0)
+        ret = 0;
 
-  close (fd);
+    close (fd);
 
-  return 1;
+    return 1;
 
 #undef PROC_IP_FORWARD
 }

-- 


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]