From: Matthias Andree <matthias.andree@gmx.de>
To: git@vger.kernel.org, gitster@pobox.com
Cc: Matthias Andree <matthias.andree@gmx.de>
Subject: [PATCH] Fix export_marks() error handling.
Date: Fri, 24 Jul 2009 10:17:13 +0200 [thread overview]
Message-ID: <1248423433-25407-1-git-send-email-matthias.andree@gmx.de> (raw)
In-Reply-To: <7v7hxyyfcg.fsf@alter.siamese.dyndns.org>
- Don't leak one FILE * on error per export_marks() call. Found with
cppcheck and reported by Martin Ettl.
- Abort the potentially long for(;idnums.size;) loop on write errors.
- Record error if fprintf() fails for reasons not required to set the
stream error indicator, such as ENOMEM.
- Add a trailing full-stop to error message when fopen() fails.
Signed-off-by: Matthias Andree <matthias.andree@gmx.de>
---
builtin-fast-export.c | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/builtin-fast-export.c b/builtin-fast-export.c
index 9a8a6fc..ca19825 100644
--- a/builtin-fast-export.c
+++ b/builtin-fast-export.c
@@ -428,21 +428,27 @@ static void export_marks(char *file)
uint32_t mark;
struct object_decoration *deco = idnums.hash;
FILE *f;
+ int e = 0;
f = fopen(file, "w");
if (!f)
- error("Unable to open marks file %s for writing", file);
+ error("Unable to open marks file %s for writing.", file);
for (i = 0; i < idnums.size; i++) {
if (deco->base && deco->base->type == 1) {
mark = ptr_to_mark(deco->decoration);
- fprintf(f, ":%"PRIu32" %s\n", mark,
- sha1_to_hex(deco->base->sha1));
+ if (fprintf(f, ":%"PRIu32" %s\n", mark,
+ sha1_to_hex(deco->base->sha1)) < 0) {
+ e = 1;
+ break;
+ }
}
deco++;
}
- if (ferror(f) || fclose(f))
+ e |= ferror(f);
+ e |= fclose(f);
+ if (e)
error("Unable to write marks file %s.", file);
}
--
1.6.3.3.413.g91e7
next parent reply other threads:[~2009-07-24 8:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <7v7hxyyfcg.fsf@alter.siamese.dyndns.org>
2009-07-24 8:17 ` Matthias Andree [this message]
2009-07-24 16:35 ` [PATCH] Fix export_marks() error handling Junio C Hamano
2009-07-09 13:01 found a resource leak in file builtin-fast-export.c Johannes Schindelin
2009-07-09 13:28 ` [PATCH] Fix export_marks() error handling Matthias Andree
2009-07-11 9:45 ` Stephen R. van den Berg
2009-07-13 8:01 ` Matthias Andree
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=1248423433-25407-1-git-send-email-matthias.andree@gmx.de \
--to=matthias.andree@gmx.de \
--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).