Message ID | patch-15.20-8deeee4278d-20221228T175512Z-avarab@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | leak fixes: various simple leak fixes | expand |
Am 28.12.22 um 19:00 schrieb Ævar Arnfjörð Bjarmason: > Follow-up 465028e0e25 (merge: add missing strbuf_release(), > 2021-10-07) and free "&msg" also when we'd "goto done" from the scope > it's allocated in. OK, but quite some trouble to go through to get one of two static strings out without leaking. > > Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> > --- > builtin/merge.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/builtin/merge.c b/builtin/merge.c > index 0f093f2a4f2..8f78f326dbe 100644 > --- a/builtin/merge.c > +++ b/builtin/merge.c > @@ -1577,6 +1577,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) > commit = remoteheads->item; > if (!commit) { > ret = 1; > + strbuf_release(&msg); > goto done; > } > > @@ -1589,6 +1590,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) > overwrite_ignore)) { > apply_autostash(git_path_merge_autostash(the_repository)); > ret = 1; > + strbuf_release(&msg); > goto done; > } > How about not using strbuf instead? builtin/merge.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/builtin/merge.c b/builtin/merge.c index 0f093f2a4f..91dd5435c5 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1560,7 +1560,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix) !common->next && oideq(&common->item->object.oid, &head_commit->object.oid)) { /* Again the most common case of merging one remote. */ - struct strbuf msg = STRBUF_INIT; + const char *msg = have_message ? + "Fast-forward (no commit created; -m option ignored)" : + "Fast-forward"; struct commit *commit; if (verbosity >= 0) { @@ -1570,10 +1572,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix) find_unique_abbrev(&remoteheads->item->object.oid, DEFAULT_ABBREV)); } - strbuf_addstr(&msg, "Fast-forward"); - if (have_message) - strbuf_addstr(&msg, - " (no commit created; -m option ignored)"); commit = remoteheads->item; if (!commit) { ret = 1; @@ -1592,9 +1590,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix) goto done; } - finish(head_commit, remoteheads, &commit->object.oid, msg.buf); + finish(head_commit, remoteheads, &commit->object.oid, msg); remove_merge_branch_state(the_repository); - strbuf_release(&msg); goto done; } else if (!remoteheads->next && common->next) ;
diff --git a/builtin/merge.c b/builtin/merge.c index 0f093f2a4f2..8f78f326dbe 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1577,6 +1577,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) commit = remoteheads->item; if (!commit) { ret = 1; + strbuf_release(&msg); goto done; } @@ -1589,6 +1590,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) overwrite_ignore)) { apply_autostash(git_path_merge_autostash(the_repository)); ret = 1; + strbuf_release(&msg); goto done; }
Follow-up 465028e0e25 (merge: add missing strbuf_release(), 2021-10-07) and free "&msg" also when we'd "goto done" from the scope it's allocated in. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- builtin/merge.c | 2 ++ 1 file changed, 2 insertions(+)