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

Re: [[RFC memory leak, v.2]] Minor memory leak fix

From
René Scharfe <l.s.r@web.de>
Date
Mar 11, 2014, 19:40 UTC
Message-ID
<531F6697.1030703@web.de>
In-Reply-To
<1394541371-2960-1-git-send-email-iveqy@iveqy.com>
Am 11.03.2014 13:36, schrieb Fredrik Gustafsson:
Show 39 quoted lines
> Strbuf needs to be released even if it's locally declared.
>
> Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>
> ---
>   archive.c | 16 ++++++++++------
>   1 file changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/archive.c b/archive.c
> index 346f3b2..dfc557d 100644
> --- a/archive.c
> +++ b/archive.c
> @@ -113,6 +113,7 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
>   	struct git_attr_check check[2];
>   	const char *path_without_prefix;
>   	int err;
> +	int to_ret = 0;
>
>   	args->convert = 0;
>   	strbuf_reset(&path);
> @@ -127,22 +128,25 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
>   	setup_archive_check(check);
>   	if (!git_check_attr(path_without_prefix, ARRAY_SIZE(check), check)) {
>   		if (ATTR_TRUE(check[0].value))
> -			return 0;
> +			goto cleanup;
>   		args->convert = ATTR_TRUE(check[1].value);
>   	}
>
>   	if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
>   		if (args->verbose)
>   			fprintf(stderr, "%.*s\n", (int)path.len, path.buf);
> -		err = write_entry(args, sha1, path.buf, path.len, mode);
> -		if (err)
> -			return err;
> -		return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
> +		to_ret = write_entry(args, sha1, path.buf, path.len, mode);
> +		if (!to_ret)
> +			to_ret = (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
> +		goto cleanup;

Why add to_ret when you can use the existing variable err directly? Or at least remove it when it's not used anymore.

Show 9 quoted lines
>   	}
>
>   	if (args->verbose)
>   		fprintf(stderr, "%.*s\n", (int)path.len, path.buf);
> -	return write_entry(args, sha1, path.buf, path.len, mode);
> +	to_ret = write_entry(args, sha1, path.buf, path.len, mode);
> +cleanup:
> +	strbuf_release(&path);
> +	return to_ret;

If you free the memory of the strbuf at the end of the function then there is no point in keeping it static anymore. Growing it to PATH_MAX also doesn't make as much sense as before then.

The patch makes git archive allocate and free the path strbuf once per archive entry, while before it allocated only once per run and left freeing to the OS. What's the performance impact of this change?

>   }
>
>   int write_archive_entries(struct archiver_args *args,
>
Previous: Fredrik GustafssonNext: Fredrik Gustafsson
Message 4 of 6 in “[RFC memory leak?] Minor memory leak fix”
  1. Fredrik GustafssonMar 11, 2014
  2. Duy NguyenMar 11, 2014
  3. [[RFC memory leak, v.2]] Minor memory leak fixFredrik Gustafsson, Mar 11, 2014
  4. René ScharfeMar 11, 2014
  5. Fredrik GustafssonMar 11, 2014
  6. Junio C HamanoMar 11, 2014

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.