[Resend Trivial PATCH] For the sake of correctness, fix file descriptor leak.

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

 



Hi, all!

    Plug a file descriptor leak.

From 9fba346aca7470633ee46848013051248493896c Mon Sep 17 00:00:00 2001
From: Andre Goddard Rosa <andre.goddard@xxxxxxxxx>
Date: Tue, 27 Nov 2007 10:16:22 -0200
Subject: [PATCH] For the sake of correctness, fix file descriptor leak.

Signed-off-by: Andre Goddard Rosa <andre.goddard@xxxxxxxxx>
---
 builtin-rerere.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/builtin-rerere.c b/builtin-rerere.c
index 7449323..31766be 100644
--- a/builtin-rerere.c
+++ b/builtin-rerere.c
@@ -275,8 +275,10 @@ static int copy_file(const char *src, const char *dest)

        if (!(in = fopen(src, "r")))
                return error("Could not open %s", src);
-       if (!(out = fopen(dest, "w")))
+       if (!(out = fopen(dest, "w"))) {
+               fclose(in);
                return error("Could not open %s", dest);
+       }
        while ((count = fread(buffer, 1, sizeof(buffer), in)))
                fwrite(buffer, 1, count, out);
        fclose(in);
--
1.5.3.6.861.gd794-dirty



-- 
[]s,
André Goddard
From 9fba346aca7470633ee46848013051248493896c Mon Sep 17 00:00:00 2001
From: Andre Goddard Rosa <andre.goddard@xxxxxxxxx>
Date: Tue, 27 Nov 2007 10:16:22 -0200
Subject: [PATCH] For the sake of correctness, fix file descriptor leak.

Signed-off-by: Andre Goddard Rosa <andre.goddard@xxxxxxxxx>
---
 builtin-rerere.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/builtin-rerere.c b/builtin-rerere.c
index 7449323..31766be 100644
--- a/builtin-rerere.c
+++ b/builtin-rerere.c
@@ -275,8 +275,10 @@ static int copy_file(const char *src, const char *dest)
 
 	if (!(in = fopen(src, "r")))
 		return error("Could not open %s", src);
-	if (!(out = fopen(dest, "w")))
+	if (!(out = fopen(dest, "w"))) {
+		fclose(in);
 		return error("Could not open %s", dest);
+	}
 	while ((count = fread(buffer, 1, sizeof(buffer), in)))
 		fwrite(buffer, 1, count, out);
 	fclose(in);
-- 
1.5.3.6.861.gd794-dirty


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux