Skip to content

Commit

Permalink
mailsplit: fix FILE* leak in split_maildir
Browse files Browse the repository at this point in the history
If we encounter an error while splitting a maildir, we exit
the function early, leaking the open filehandle. This isn't
a big deal, since we exit the program soon after, but it's
easy enough to be careful.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Sep 25, 2015
1 parent 7cd17e8 commit d270d7b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion builtin/mailsplit.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ static int split_maildir(const char *maildir, const char *dir,
{
char file[PATH_MAX];
char name[PATH_MAX];
FILE *f = NULL;
int ret = -1;
int i;
struct string_list list = STRING_LIST_INIT_DUP;
Expand All @@ -160,7 +161,6 @@ static int split_maildir(const char *maildir, const char *dir,
goto out;

for (i = 0; i < list.nr; i++) {
FILE *f;
snprintf(file, sizeof(file), "%s/%s", maildir, list.items[i].string);
f = fopen(file, "r");
if (!f) {
Expand All @@ -177,10 +177,13 @@ static int split_maildir(const char *maildir, const char *dir,
split_one(f, name, 1);

fclose(f);
f = NULL;
}

ret = skip;
out:
if (f)
fclose(f);
string_list_clear(&list, 1);
return ret;
}
Expand Down

0 comments on commit d270d7b

Please sign in to comment.