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

Re: [PATCH] update-index: fix xgetcwd() related memory leak

From
Jeff King <peff@peff.net>
Date
Mar 30, 2017, 06:23 UTC
Message-ID
<20170330062337.rwd2u5k7s57zczuo@sigill.intra.peff.net>
In-Reply-To
<20170330062208.29018-1-chriscool@tuxfamily.org>
On Thu, Mar 30, 2017 at 08:22:08AM +0200, Christian Couder wrote:
Show 30 quoted lines
> As xgetcwd() returns an allocated buffer, we should free this
> buffer when we don't need it any more.
> 
> This was found by Coverity.
> 
> Reported-by: Jeff King <peff@peff.net>
> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
> ---
>  builtin/update-index.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/builtin/update-index.c b/builtin/update-index.c
> index d74d72cc7f..ebfc09faa0 100644
> --- a/builtin/update-index.c
> +++ b/builtin/update-index.c
> @@ -125,12 +125,16 @@ static int test_if_untracked_cache_is_supported(void)
>  	struct stat st;
>  	struct stat_data base;
>  	int fd, ret = 0;
> +	char *cwd;
>  
>  	strbuf_addstr(&mtime_dir, "mtime-test-XXXXXX");
>  	if (!mkdtemp(mtime_dir.buf))
>  		die_errno("Could not make temporary directory");
>  
> -	fprintf(stderr, _("Testing mtime in '%s' "), xgetcwd());
> +	cwd = xgetcwd();
> +	fprintf(stderr, _("Testing mtime in '%s' "), cwd);
> +	free(cwd);
> +
Yep, this solution looks obviously correct to me.
-Peff
Previous: Christian Couder
Message 2 of 2 in “update-index: fix xgetcwd() related memory leak”
  1. update-index: fix xgetcwd() related memory leakChristian Couder, Mar 30, 2017
  2. Jeff KingMar 30, 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.