Skip to content

Commit 15d980a

Browse files
pcloudsgitster
authored andcommitted
log: fix memory leak in open_next_file()
Noticed-by: Jeff King <[email protected]> Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f7566f0 commit 15d980a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

builtin/log.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -842,8 +842,10 @@ static int open_next_file(struct commit *commit, const char *subject,
842842
if (output_directory) {
843843
strbuf_addstr(&filename, output_directory);
844844
if (filename.len >=
845-
PATH_MAX - FORMAT_PATCH_NAME_MAX - suffix_len)
845+
PATH_MAX - FORMAT_PATCH_NAME_MAX - suffix_len) {
846+
strbuf_release(&filename);
846847
return error(_("name of output directory is too long"));
848+
}
847849
strbuf_complete(&filename, '/');
848850
}
849851

@@ -857,9 +859,11 @@ static int open_next_file(struct commit *commit, const char *subject,
857859
if (!quiet)
858860
printf("%s\n", filename.buf + outdir_offset);
859861

860-
if ((rev->diffopt.file = fopen(filename.buf, "w")) == NULL)
861-
return error_errno(_("Cannot open patch file %s"),
862-
filename.buf);
862+
if ((rev->diffopt.file = fopen(filename.buf, "w")) == NULL) {
863+
error_errno(_("Cannot open patch file %s"), filename.buf);
864+
strbuf_release(&filename);
865+
return -1;
866+
}
863867

864868
strbuf_release(&filename);
865869
return 0;

0 commit comments

Comments
 (0)