Re: [PATCH 15/20] builtin/merge.c: always free "struct strbuf msg"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
> ---
>  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)
 		;




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux