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

Re: [PATCH 08/11] checkout: add a missing clear_unpack_trees_porcelain()

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jun 30, 2022, 23:34 UTC
Message-ID
<220701.86wncxbu7q.gmgdl@evledraar.gmail.com>
In-Reply-To
<xmqq35fldc9i.fsf@gitster.g>
On Thu, Jun 30 2022, Junio C Hamano wrote:
Show 30 quoted lines
> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>
>> In 1c41d2805e4 (unpack_trees_options: free messages when done,
>> 2018-05-21) we started calling clear_unpack_trees_porcelain() on this
>> codepath, but missed this error path, let's also clear what we've
>> allocated in that case.
>>
>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
>> ---
>>  builtin/checkout.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/builtin/checkout.c b/builtin/checkout.c
>> index 2eefda81d8c..3d6762106e8 100644
>> --- a/builtin/checkout.c
>> +++ b/builtin/checkout.c
>> @@ -750,6 +750,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
>>  		refresh_cache(REFRESH_QUIET);
>>  
>>  		if (unmerged_cache()) {
>> +			clear_unpack_trees_porcelain(&topts);
>>  			error(_("you need to resolve your current index first"));
>>  			return 1;
>>  		}
>
> Does refresh_cache(REFRESH_QUIET) depend on the porcelain error
> messages already set?  If not another way to fix it may be to delay
> the call to setup_unpack_trees_porcelain() until it becomes needed.
>
> But the patch as posted is certainly an improvement.
Yes, that would work too, I can do it that way if you'd like.

I was trying to keep these fixes as narrow as possible, and resist any temptations to re-arrange code so as to avoid allocations, which we can often do, but then instead of a 1-line diff it's 10, 50, 100... :)

In this case it'll be somewhere around 10, and just a code-move, so maybe that's fine...

Previous: Junio C HamanoNext: Junio C Hamano
Message 13 of 31 in “built-ins: fix common memory leaks”
  1. 00/11 built-ins: fix common memory leaksÆvar Arnfjörð Bjarmason, Jun 30, 2022
  2. 01/11 check-ref-format: fix trivial memory leakÆvar Arnfjörð Bjarmason, Jun 30, 2022
  3. Junio C HamanoJun 30, 2022
  4. 02/11 clone: fix memory leak in copy_ref() callÆvar Arnfjörð Bjarmason, Jun 30, 2022
  5. Junio C HamanoJun 30, 2022
  6. 03/11 submodule.c: free() memory from xgetcwd()Ævar Arnfjörð Bjarmason, Jun 30, 2022
  7. 04/11 revert: free "struct replay_opts" membersÆvar Arnfjörð Bjarmason, Jun 30, 2022
  8. 05/11 cat-file: fix a memory leak in --batch-command modeÆvar Arnfjörð Bjarmason, Jun 30, 2022
  9. 06/11 merge-file: refactor for subsequent memory leak fixÆvar Arnfjörð Bjarmason, Jun 30, 2022
  10. 07/11 merge-file: fix memory leaks on error pathÆvar Arnfjörð Bjarmason, Jun 30, 2022
  11. 08/11 checkout: add a missing clear_unpack_trees_porcelain()Ævar Arnfjörð Bjarmason, Jun 30, 2022
  12. Junio C HamanoJun 30, 2022
  13. Ævar Arnfjörð BjarmasonJun 30, 2022
  14. Junio C HamanoJun 30, 2022
  15. 09/11 gc: fix a memory leakÆvar Arnfjörð Bjarmason, Jun 30, 2022
  16. 10/11 cat-file: fix a common "struct object_context" memory leakÆvar Arnfjörð Bjarmason, Jun 30, 2022
  17. 11/11 pull: fix a "struct oid_array" memory leakÆvar Arnfjörð Bjarmason, Jun 30, 2022
  18. 00/11 built-ins: fix common memory leaksÆvar Arnfjörð Bjarmason, Jul 1, 2022
  19. 01/11 check-ref-format: fix trivial memory leakÆvar Arnfjörð Bjarmason, Jul 1, 2022
  20. 02/11 clone: fix memory leak in wanted_peer_refs()Ævar Arnfjörð Bjarmason, Jul 1, 2022
  21. 03/11 submodule.c: free() memory from xgetcwd()Ævar Arnfjörð Bjarmason, Jul 1, 2022
  22. 04/11 revert: free "struct replay_opts" membersÆvar Arnfjörð Bjarmason, Jul 1, 2022
  23. 05/11 cat-file: fix a memory leak in --batch-command modeÆvar Arnfjörð Bjarmason, Jul 1, 2022
  24. 06/11 merge-file: refactor for subsequent memory leak fixÆvar Arnfjörð Bjarmason, Jul 1, 2022
  25. 09/11 gc: fix a memory leakÆvar Arnfjörð Bjarmason, Jul 1, 2022
  26. 08/11 checkout: avoid "struct unpack_trees_options" leakÆvar Arnfjörð Bjarmason, Jul 1, 2022
  27. Junio C HamanoJul 1, 2022
  28. 07/11 merge-file: fix memory leaks on error pathÆvar Arnfjörð Bjarmason, Jul 1, 2022
  29. 10/11 cat-file: fix a common "struct object_context" memory leakÆvar Arnfjörð Bjarmason, Jul 1, 2022
  30. 11/11 pull: fix a "struct oid_array" memory leakÆvar Arnfjörð Bjarmason, Jul 1, 2022
  31. Junio C HamanoJul 1, 2022

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.