apply: free unused fragments for submodule patch

We simply discarded the fragments that we are not going to use upon seeing a patch to update the submodule commit bound at path that we have not checked out. Free these fragments, not to leak them. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Mar 28, 2012 at 23:22 UTC 9d16c2d51412c3ebf06f88faddde3610d6e21892
1 file changed +15 -9
builtin/apply.c
+15 -9
@@ -196,17 +196,20 @@ struct patch {
196 struct patch *next;
197 };
198
199 -static void free_patch(struct patch *patch)
199 +static void free_fragment_list(struct fragment *list)
200 {
201 - struct fragment *fragment = patch->fragments;
202 -
203 - while (fragment) {
204 - struct fragment *fragment_next = fragment->next;
205 - if (fragment->patch != NULL && fragment->free_patch)
206 - free((char *)fragment->patch);
207 - free(fragment);
208 - fragment = fragment_next;
201 + while (list) {
202 + struct fragment *next = list->next;
203 + if (list->free_patch)
204 + free((char *)list->patch);
205 + free(list);
206 + list = next;
207 }
208 +}
209 +
210 +static void free_patch(struct patch *patch)
211 +{
212 + free_fragment_list(patch->fragments);
213 free(patch->def_name);
214 free(patch->old_name);
215 free(patch->new_name);
@@ -2992,7 +2995,10 @@ static int apply_data(struct patch *patch, struct stat *st, struct cache_entry *
2995 /*
2996 * There is no way to apply subproject
2997 * patch without looking at the index.
2998 + * NEEDSWORK: shouldn't this be flagged
2999 + * as an error???
3000 */
3001 + free_fragment_list(patch->fragments);
3002 patch->fragments = NULL;
3003 }
3004 } else {