diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-06-04 10:21:01 +0900 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-06-04 10:21:01 +0900 |
commit | 70d19a436dfdc2375f7c80dac85bc08160f6a0f7 (patch) | |
tree | e3ff9069fadda6441f29d029a1d242676e029340 /builtin/am.c | |
parent | 8a17b259e2c9137c1653523e00a988cb3cee3a1f (diff) | |
parent | 721f5f1e355648f6b15d79799a3fdc6b4a28352f (diff) | |
download | git-70d19a436dfdc2375f7c80dac85bc08160f6a0f7.tar.gz |
Merge branch 'jk/am-leakfix' into maint
The codepath in "git am" that is used when running "git rebase"
leaked memory held for the log message of the commits being rebased.
* jk/am-leakfix:
am: shorten ident_split variable name in get_commit_info()
am: simplify allocations in get_commit_info()
am: fix commit buffer leak in get_commit_info()
Diffstat (limited to 'builtin/am.c')
-rw-r--r-- | builtin/am.c | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/builtin/am.c b/builtin/am.c index dd60fad1e6..7d39156ff3 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1372,40 +1372,33 @@ static int get_mail_commit_oid(struct object_id *commit_id, const char *mail) */ static void get_commit_info(struct am_state *state, struct commit *commit) { - const char *buffer, *ident_line, *author_date, *msg; + const char *buffer, *ident_line, *msg; size_t ident_len; - struct ident_split ident_split; - struct strbuf sb = STRBUF_INIT; + struct ident_split id; buffer = logmsg_reencode(commit, NULL, get_commit_output_encoding()); ident_line = find_commit_header(buffer, "author", &ident_len); - if (split_ident_line(&ident_split, ident_line, ident_len) < 0) { - strbuf_add(&sb, ident_line, ident_len); - die(_("invalid ident line: %s"), sb.buf); - } + if (split_ident_line(&id, ident_line, ident_len) < 0) + die(_("invalid ident line: %.*s"), (int)ident_len, ident_line); assert(!state->author_name); - if (ident_split.name_begin) { - strbuf_add(&sb, ident_split.name_begin, - ident_split.name_end - ident_split.name_begin); - state->author_name = strbuf_detach(&sb, NULL); - } else + if (id.name_begin) + state->author_name = + xmemdupz(id.name_begin, id.name_end - id.name_begin); + else state->author_name = xstrdup(""); assert(!state->author_email); - if (ident_split.mail_begin) { - strbuf_add(&sb, ident_split.mail_begin, - ident_split.mail_end - ident_split.mail_begin); - state->author_email = strbuf_detach(&sb, NULL); - } else + if (id.mail_begin) + state->author_email = + xmemdupz(id.mail_begin, id.mail_end - id.mail_begin); + else state->author_email = xstrdup(""); - author_date = show_ident_date(&ident_split, DATE_MODE(NORMAL)); - strbuf_addstr(&sb, author_date); assert(!state->author_date); - state->author_date = strbuf_detach(&sb, NULL); + state->author_date = xstrdup(show_ident_date(&id, DATE_MODE(NORMAL))); assert(!state->msg); msg = strstr(buffer, "\n\n"); @@ -1413,6 +1406,7 @@ static void get_commit_info(struct am_state *state, struct commit *commit) die(_("unable to parse commit %s"), oid_to_hex(&commit->object.oid)); state->msg = xstrdup(msg + 2); state->msg_len = strlen(state->msg); + unuse_commit_buffer(commit, buffer); } /** |