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 } --