Skip to content

Commit e5dd0a0

Browse files
brandb97gitster
authored andcommitted
builtin/am: fix memory leak in split_mail_stgit_series
In builtin/am.c:split_mail_stgit_series, if `fopen` failed, `series_dir_buf` allocated by `xstrdup` will leak. Add `free` in `!fp` if branch will prevent the leak. Signed-off-by: Lidong Yan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2f323bb commit e5dd0a0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

builtin/am.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,8 +848,10 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths,
848848
series_dir = dirname(series_dir_buf);
849849

850850
fp = fopen(*paths, "r");
851-
if (!fp)
851+
if (!fp) {
852+
free(series_dir_buf);
852853
return error_errno(_("could not open '%s' for reading"), *paths);
854+
}
853855

854856
while (!strbuf_getline_lf(&sb, fp)) {
855857
if (*sb.buf == '#')

0 commit comments

Comments
 (0)