git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 2/3] refs: add option core.logAllRefUpdates = always

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 30, 2017, 22:57 UTC
Message-ID
<xmqq8tpstaus.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<xmqq37g0us5p.fsf@gitster.mtv.corp.google.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 17 quoted lines
>> diff --git a/builtin/checkout.c b/builtin/checkout.c
>> index bfe685c..81ea2ed 100644
>> --- a/builtin/checkout.c
>> +++ b/builtin/checkout.c
>> @@ -612,14 +612,12 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
>>  	const char *old_desc, *reflog_msg;
>>  	if (opts->new_branch) {
>>  		if (opts->new_orphan_branch) {
>> -			if (opts->new_branch_log && !log_all_ref_updates) {
>> +			const char *refname = mkpathdup("refs/heads/%s", opts->new_orphan_branch);
>> ...
>>  				if (ret) {
>>  					fprintf(stderr, _("Can not do reflog for '%s': %s\n"),
>>  						opts->new_orphan_branch, err.buf);
>
> Here you need to have another free(), as this block makes an early
> return and you end up leaking refname.
I am building with the attached patch squashed on top.  

The extra free(refname) is to plug the leak I pointed out, and the type of refname is no longer const, because "const char *" cannot be free()d without casting, and in this codepath I do not see a reason to mark it as const.

When queued on top of 4e59582ff7 ("Seventh batch for 2.12", 2017-01-23), however, this fails t2017#9 (orphan with -l makes reflog when core.logAllRefUpdates = false).

diff --git a/builtin/checkout.c b/builtin/checkout.c
index 81ea2eda99..e1a60fd8ea 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -612,7 +612,9 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
 	const char *old_desc, *reflog_msg;
 	if (opts->new_branch) {
 		if (opts->new_orphan_branch) {
-			const char *refname = mkpathdup("refs/heads/%s", opts->new_orphan_branch);
+			char *refname;
+
+			refname = mkpathdup("refs/heads/%s", opts->new_orphan_branch);
 			if (opts->new_branch_log && should_autocreate_reflog(refname)) {
 				int ret;
 				struct strbuf err = STRBUF_INIT;
@@ -622,6 +624,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
 					fprintf(stderr, _("Can not do reflog for '%s': %s\n"),
 						opts->new_orphan_branch, err.buf);
 					strbuf_release(&err);
+					free(refname);
 					return;
 				}
 				strbuf_release(&err);
Previous: Junio C HamanoNext: Cornelius Weig
Message 25 of 33 in “tag: add tag.createReflog option”
  1. tag: add tag.createReflog optioncornelius.weig@tngtech.com, Jan 25, 2017
  2. Pranit BauvaJan 25, 2017
  3. Jeff KingJan 25, 2017
  4. Junio C HamanoJan 25, 2017
  5. Cornelius WeigJan 25, 2017
  6. Jeff KingJan 25, 2017
  7. Junio C HamanoJan 25, 2017
  8. Junio C HamanoJan 25, 2017
  9. Cornelius WeigJan 25, 2017
  10. refs: add option core.logAllRefUpdates = alwayscornelius.weig@tngtech.com, Jan 26, 2017
  11. refs: add option core.logAllRefUpdates = alwayscornelius.weig@tngtech.com, Jan 26, 2017
  12. Jeff KingJan 26, 2017
  13. Cornelius WeigJan 26, 2017
  14. Jeff KingJan 26, 2017
  15. 1/3 config: add markup to core.logAllRefUpdates doccornelius.weig@tngtech.com, Jan 26, 2017
  16. 2/3 refs: add option core.logAllRefUpdates = alwayscornelius.weig@tngtech.com, Jan 26, 2017
  17. Junio C HamanoJan 26, 2017
  18. 3/3 update-ref: add test cases for bare repositorycornelius.weig@tngtech.com, Jan 26, 2017
  19. Junio C HamanoJan 26, 2017
  20. Junio C HamanoJan 26, 2017
  21. 1/3 config: add markup to core.logAllRefUpdates doccornelius.weig@tngtech.com, Jan 27, 2017
  22. 3/3 update-ref: add test cases for bare repositorycornelius.weig@tngtech.com, Jan 27, 2017
  23. 2/3 refs: add option core.logAllRefUpdates = alwayscornelius.weig@tngtech.com, Jan 27, 2017
  24. Junio C HamanoJan 30, 2017
  25. Junio C HamanoJan 30, 2017
  26. Cornelius WeigJan 31, 2017
  27. Junio C HamanoJan 31, 2017
  28. Jeff KingJan 30, 2017
  29. Cornelius WeigJan 31, 2017
  30. Jeff KingJan 31, 2017
  31. Junio C HamanoJan 31, 2017
  32. Cornelius WeigJan 31, 2017
  33. Junio C HamanoJan 31, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.