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

Re: [PATCH 04/10] name-rev: don't leak path copy in name_ref()

From
Derrick Stolee <stolee@gmail.com>
Date
Feb 5, 2020, 14:35 UTC
Message-ID
<1cced7f0-8112-1ed9-b25d-e559a17a3cc0@gmail.com>
In-Reply-To
<32a0a2d6-3237-24e9-c647-6624cc2a1e89@web.de>
On 2/4/2020 4:17 PM, René Scharfe wrote:
Show 20 quoted lines
> name_ref() duplicates the path string and passes it to name_rev(), which
> either puts it into a commit slab or ignores it if there is already a
> better name, leaking it.  Move the duplication to name_rev() and release
> the copy in the latter case.
> 
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
>  builtin/name-rev.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/builtin/name-rev.c b/builtin/name-rev.c
> index 2e6820bd5b..3e22a0503e 100644
> --- a/builtin/name-rev.c
> +++ b/builtin/name-rev.c
> @@ -121,6 +121,8 @@ static void name_rev(struct commit *start_commit,
> 
>  	if (deref)
>  		tip_name = to_free = xstrfmt("%s^0", tip_name);
> +	else
> +		tip_name = to_free = xstrdup(tip_name);

We now unconditionally duplicate the input tip_name and free it within the method. Good.

Show 8 quoted lines
>  	if (!create_or_update_name(start_commit, tip_name, taggerdate, 0, 0,
>  				   from_tag)) {
> @@ -323,7 +325,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
>  		if (taggerdate == TIME_MAX)
>  			taggerdate = commit->date;
>  		path = name_ref_abbrev(path, can_abbreviate_output);
> -		name_rev(commit, xstrdup(path), taggerdate, from_tag, deref);
> +		name_rev(commit, path, taggerdate, from_tag, deref);

And we no longer duplicate 'path' here, as it is unconditionally duplicated in name_ref().

Thanks, -Stolee

Previous: René ScharfeNext: René Scharfe
Message 10 of 27 in “name-rev: improve memory usage”
  1. 00/10 name-rev: improve memory usageRené Scharfe, Feb 4, 2020
  2. 01/10 name-rev: rewrite create_or_update_name()René Scharfe, Feb 4, 2020
  3. Derrick StoleeFeb 5, 2020
  4. Taylor BlauFeb 5, 2020
  5. Andrei RybakFeb 5, 2020
  6. René ScharfeFeb 5, 2020
  7. 02/10 name-rev: remove unused typedefRené Scharfe, Feb 4, 2020
  8. 03/10 name-rev: respect const qualifierRené Scharfe, Feb 4, 2020
  9. 04/10 name-rev: don't leak path copy in name_ref()René Scharfe, Feb 4, 2020
  10. Derrick StoleeFeb 5, 2020
  11. 05/10 name-rev: don't _peek() in create_or_update_name()René Scharfe, Feb 4, 2020
  12. 06/10 name-rev: put struct rev_name into commit slabRené Scharfe, Feb 4, 2020
  13. 07/10 name-rev: factor out get_parent_name()René Scharfe, Feb 4, 2020
  14. 08/10 name-rev: pre-size buffer in get_parent_name()René Scharfe, Feb 4, 2020
  15. Derrick StoleeFeb 5, 2020
  16. René ScharfeFeb 5, 2020
  17. 09/10 name-rev: generate name strings only if they are betterRené Scharfe, Feb 4, 2020
  18. Derrick StoleeFeb 5, 2020
  19. René ScharfeFeb 5, 2020
  20. 10/10 name-rev: release unused name stringsRené Scharfe, Feb 4, 2020
  21. Derrick StoleeFeb 5, 2020
  22. Derrick StoleeFeb 5, 2020
  23. Derrick StoleeFeb 5, 2020
  24. 01/10 name-rev: rewrite create_or_update_name()René Scharfe, Feb 5, 2020
  25. 11/10 name-rev: sort tip names before applyingRené Scharfe, Feb 5, 2020
  26. Junio C HamanoFeb 5, 2020
  27. René ScharfeFeb 5, 2020

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.