]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/am: fix memory leak in `split_mail_stgit_series`
authorLidong Yan <502024330056@smail.nju.edu.cn>
Mon, 12 May 2025 02:07:27 +0000 (02:07 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 12 May 2025 17:28:16 +0000 (10:28 -0700)
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 <502024330056@smail.nju.edu.cn>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/am.c

index d1990d7edcbe37467c59a420a9b03a5894e6da93..bb36b42aa1deb56cf8456f262b66d64c40b1ccc4 100644 (file)
@@ -848,8 +848,10 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths,
        series_dir = dirname(series_dir_buf);
 
        fp = fopen(*paths, "r");
-       if (!fp)
+       if (!fp) {
+               free(series_dir_buf);
                return error_errno(_("could not open '%s' for reading"), *paths);
+       }
 
        while (!strbuf_getline_lf(&sb, fp)) {
                if (*sb.buf == '#')