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

Re: [PATCH v2 5/9] builtin/repack.c: avoid leaking child arguments

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 27, 2021, 23:44 UTC
Message-ID
<xmqqzgqut4lr.fsf@gitster.g>
In-Reply-To
<bcd12ecab81029be825a646348cb7ae69970a819.1635282024.git.me@ttaylorr.com>
Taylor Blau <me@ttaylorr.com> writes:
Show 9 quoted lines
> @@ -586,8 +588,10 @@ static int write_midx_included_packs(struct string_list *include,
>  		strvec_pushf(&cmd.args, "--refs-snapshot=%s", refs_snapshot);
>  
>  	ret = start_command(&cmd);
> -	if (ret)
> +	if (ret) {
> +		child_process_clear(&cmd);
>  		return ret;
> +	}

This happens only when start_command() returns an error. But the function always calls child_process_clear() before doing so.

So I am not sure if this hunk is needed. It didn't exist in v1, if I recall correctly. Am I missing something obvious?

Show 18 quoted lines
> @@ -608,9 +612,10 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
>  	struct pack_geometry *geometry = NULL;
>  	struct strbuf line = STRBUF_INIT;
>  	struct tempfile *refs_snapshot = NULL;
> -	int i, ext, ret;
> +	int i, ext, ret = 0;
>  	FILE *out;
>  	int show_progress = isatty(2);
> +	int cmd_cleared = 0;
>  
>  	/* variables to be filled by option parsing */
>  	int pack_everything = 0;
> @@ -794,7 +799,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
>  
>  	ret = start_command(&cmd);
>  	if (ret)
> -		return ret;
> +		goto cleanup;

Likewise, at this point, start_command() should have already cleared cmd before it returned an error, no?

Show 8 quoted lines
> @@ -818,8 +823,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
>  	}
>  	fclose(out);
>  	ret = finish_command(&cmd);
> +	cmd_cleared = 1;
>  	if (ret)
> -		return ret;
> +		goto cleanup;

And cmd is also cleared after we pass this point. So perhaps after the cleanup label, there is no need to call child_process_clear() at all, no?

Previous: Taylor BlauNext: Taylor Blau
Message 7 of 13 in “midx: clean up t5319 under 'SANITIZE=leak'”
  1. 0/9 midx: clean up t5319 under 'SANITIZE=leak'Taylor Blau, Oct 26, 2021
  2. 1/9 midx.c: clean up chunkfile after reading the MIDXTaylor Blau, Oct 26, 2021
  3. 2/9 midx.c: don't leak MIDX from verify_midx_fileTaylor Blau, Oct 26, 2021
  4. 3/9 t/helper/test-read-midx.c: free MIDX within read_midx_file()Taylor Blau, Oct 26, 2021
  5. 4/9 builtin/pack-objects.c: don't leak memory via argumentsTaylor Blau, Oct 26, 2021
  6. 5/9 builtin/repack.c: avoid leaking child argumentsTaylor Blau, Oct 26, 2021
  7. Junio C HamanoOct 27, 2021
  8. Taylor BlauOct 28, 2021
  9. 6/9 builtin/multi-pack-index.c: don't leak concatenated optionsTaylor Blau, Oct 26, 2021
  10. 7/9 midx.c: write MIDX filenames to strbufTaylor Blau, Oct 26, 2021
  11. 8/9 pack-bitmap.c: don't leak type-level bitmapsTaylor Blau, Oct 26, 2021
  12. 9/9 pack-bitmap.c: more aggressively free in free_bitmap_index()Taylor Blau, Oct 26, 2021
  13. Junio C HamanoOct 27, 2021

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.