Skip to content

Commit 96d69b5

Browse files
mandreegitster
authored andcommitted
Fix export_marks() error handling.
- 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7e9ff00 commit 96d69b5

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

builtin-fast-export.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,21 +428,27 @@ static void export_marks(char *file)
428428
uint32_t mark;
429429
struct object_decoration *deco = idnums.hash;
430430
FILE *f;
431+
int e = 0;
431432

432433
f = fopen(file, "w");
433434
if (!f)
434-
error("Unable to open marks file %s for writing", file);
435+
error("Unable to open marks file %s for writing.", file);
435436

436437
for (i = 0; i < idnums.size; i++) {
437438
if (deco->base && deco->base->type == 1) {
438439
mark = ptr_to_mark(deco->decoration);
439-
fprintf(f, ":%"PRIu32" %s\n", mark,
440-
sha1_to_hex(deco->base->sha1));
440+
if (fprintf(f, ":%"PRIu32" %s\n", mark,
441+
sha1_to_hex(deco->base->sha1)) < 0) {
442+
e = 1;
443+
break;
444+
}
441445
}
442446
deco++;
443447
}
444448

445-
if (ferror(f) || fclose(f))
449+
e |= ferror(f);
450+
e |= fclose(f);
451+
if (e)
446452
error("Unable to write marks file %s.", file);
447453
}
448454

0 commit comments

Comments
 (0)