diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2017-05-03 17:16:56 +0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-05-26 12:33:56 +0900 |
commit | 15d980a785f8c962bc032df40cb42fdc269c9dc6 (patch) | |
tree | f02823d94d56863e09ee98d2d7b875d691402420 /builtin | |
parent | rerere.c: move error_errno() closer to the source system call (diff) | |
download | tgif-15d980a785f8c962bc032df40cb42fdc269c9dc6.tar.xz |
log: fix memory leak in open_next_file()
Noticed-by: Jeff King <peff@peff.net>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/log.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/builtin/log.c b/builtin/log.c index 26d6a3cf14..f075838df9 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -842,8 +842,10 @@ static int open_next_file(struct commit *commit, const char *subject, if (output_directory) { strbuf_addstr(&filename, output_directory); if (filename.len >= - PATH_MAX - FORMAT_PATCH_NAME_MAX - suffix_len) + PATH_MAX - FORMAT_PATCH_NAME_MAX - suffix_len) { + strbuf_release(&filename); return error(_("name of output directory is too long")); + } strbuf_complete(&filename, '/'); } @@ -857,9 +859,11 @@ static int open_next_file(struct commit *commit, const char *subject, if (!quiet) printf("%s\n", filename.buf + outdir_offset); - if ((rev->diffopt.file = fopen(filename.buf, "w")) == NULL) - return error_errno(_("Cannot open patch file %s"), - filename.buf); + if ((rev->diffopt.file = fopen(filename.buf, "w")) == NULL) { + error_errno(_("Cannot open patch file %s"), filename.buf); + strbuf_release(&filename); + return -1; + } strbuf_release(&filename); return 0; |