git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "André Goddard Rosa" <andre.goddard@gmail.com>
To: "Junio C Hamano" <gitster@pobox.com>
Cc: "Git Mailing List" <git@vger.kernel.org>
Subject: [Resend Trivial PATCH] For the sake of correctness, fix file descriptor leak.
Date: Sun, 25 Nov 2007 19:37:05 -0200	[thread overview]
Message-ID: <b8bf37780711251337q41e02304q8fd2654b1e83201@mail.gmail.com> (raw)
In-Reply-To: <b8bf37780711211659v4fbd5936t29d0a0a2ff84f4b@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1077 bytes --]

Hi, all!

    Plug a file descriptor leak.

From 9fba346aca7470633ee46848013051248493896c Mon Sep 17 00:00:00 2001
From: Andre Goddard Rosa <andre.goddard@gmail.com>
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@gmail.com>
---
 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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-For-the-sake-of-correctness-fix-file-descriptor-le.patch --]
[-- Type: text/x-patch; name=0002-For-the-sake-of-correctness-fix-file-descriptor-le.patch, Size: 921 bytes --]

From 9fba346aca7470633ee46848013051248493896c Mon Sep 17 00:00:00 2001
From: Andre Goddard Rosa <andre.goddard@gmail.com>
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@gmail.com>
---
 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


  reply	other threads:[~2007-11-25 21:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-22  0:59 [PATCH] For the sake of correctness, fix file descriptor leak André Goddard Rosa
2007-11-25 21:37 ` André Goddard Rosa [this message]
2007-11-25 22:29   ` [Resend Trivial PATCH] " Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b8bf37780711251337q41e02304q8fd2654b1e83201@mail.gmail.com \
    --to=andre.goddard@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).