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

Re: [PATCH 2/3] Fix memory leak in apply_patch in apply.c.

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 3, 2012, 07:41 UTC
Message-ID
<7v399q8732.fsf@alter.siamese.dyndns.org>
In-Reply-To
<03cc2ba05a5744d8b48700556f1942757151ec4b.1330740964.git.jaredhance@gmail.com>
Jared Hance <jaredhance@gmail.com> writes:
Show 6 quoted lines
> @@ -3712,7 +3712,6 @@ static int apply_patch(int fd, const char *filename, int options)
>  			listp = &patch->next;
>  		}
>  		else {
> -			/* perhaps free it a bit better? */
>  			free(patch);

This "free it better" comment is not about how to free the "struct patch" itself, but is about the piece of memory pointed at it, "struct fragment", and pieces of patch text pointed at them. The patch text pointed with frag->patch starts out as a location in buf.buf (which will be freed later in this function), but IIRC there were places deeper in the callchain that replace the pointer with allocated memory.

Show 9 quoted lines
>  			skipped_patch++;
>  		}
> @@ -3753,6 +3752,13 @@ static int apply_patch(int fd, const char *filename, int options)
>  
>  	if (summary)
>  		summary_patch_list(list);
> +	
> +	patch_iter = list;
> +	while(patch_iter != NULL) {
	while (patch_iter) {
Show 7 quoted lines
> +	    struct patch *patch_iter_next = patch_iter->next;
> +	    free(patch_iter);
> +	    patch_iter = patch_iter_next;
> +	}
>  
>  	strbuf_release(&buf);
>  	return 0;
Previous: Jared HanceNext: Jared Hance
Message 8 of 18 in “Fix some documented fixmes”
  1. 0/3 Fix some documented fixmesJared Hance, Mar 3, 2012
  2. 1/3 Use startup_info->prefix rather than prefix.Jared Hance, Mar 3, 2012
  3. Junio C HamanoMar 3, 2012
  4. Nguyen Thai Ngoc DuyMar 3, 2012
  5. Junio C HamanoMar 3, 2012
  6. Jared HanceMar 3, 2012
  7. 2/3 Fix memory leak in apply_patch in apply.c.Jared Hance, Mar 3, 2012
  8. Junio C HamanoMar 3, 2012
  9. 3/3 Add threaded versions of functions in symlinks.c.Jared Hance, Mar 3, 2012
  10. Junio C HamanoMar 3, 2012
  11. 0/3 Fix a few documents fixmesJared Hance, Mar 3, 2012
  12. 1/3 Use startup_info->prefix rather than prefix.Jared Hance, Mar 3, 2012
  13. Jeff EplerMar 3, 2012
  14. 2/3 Fix memory leak in apply_patch in apply.c.Jared Hance, Mar 3, 2012
  15. Jared HanceMar 3, 2012
  16. Junio C HamanoMar 3, 2012
  17. 3/3 Add threaded versions of functions in symlinks.c.Jared Hance, Mar 3, 2012
  18. Thomas RastMar 5, 2012

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.