Skip to content

Commit d270d7b

Browse files
peffgitster
authored andcommitted
mailsplit: fix FILE* leak in split_maildir
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7cd17e8 commit d270d7b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

builtin/mailsplit.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ static int split_maildir(const char *maildir, const char *dir,
150150
{
151151
char file[PATH_MAX];
152152
char name[PATH_MAX];
153+
FILE *f = NULL;
153154
int ret = -1;
154155
int i;
155156
struct string_list list = STRING_LIST_INIT_DUP;
@@ -160,7 +161,6 @@ static int split_maildir(const char *maildir, const char *dir,
160161
goto out;
161162

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

179179
fclose(f);
180+
f = NULL;
180181
}
181182

182183
ret = skip;
183184
out:
185+
if (f)
186+
fclose(f);
184187
string_list_clear(&list, 1);
185188
return ret;
186189
}

0 commit comments

Comments
 (0)