Thread (1 message) 1 message, 1 author, 2016-06-15

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

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:53:12

Jared Hance [off-list ref] writes:
quoted hunk
@@ -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.
quoted hunk
 			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) {
+	    struct patch *patch_iter_next = patch_iter->next;
+	    free(patch_iter);
+	    patch_iter = patch_iter_next;
+	}
 
 	strbuf_release(&buf);
 	return 0;
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help