Skip to content

Commit 9d16c2d

Browse files
committed
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 <[email protected]>
1 parent 8192a2f commit 9d16c2d

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

builtin/apply.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,20 @@ struct patch {
196196
struct patch *next;
197197
};
198198

199-
static void free_patch(struct patch *patch)
199+
static void free_fragment_list(struct fragment *list)
200200
{
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;
209207
}
208+
}
209+
210+
static void free_patch(struct patch *patch)
211+
{
212+
free_fragment_list(patch->fragments);
210213
free(patch->def_name);
211214
free(patch->old_name);
212215
free(patch->new_name);
@@ -2992,7 +2995,10 @@ static int apply_data(struct patch *patch, struct stat *st, struct cache_entry *
29922995
/*
29932996
* There is no way to apply subproject
29942997
* patch without looking at the index.
2998+
* NEEDSWORK: shouldn't this be flagged
2999+
* as an error???
29953000
*/
3001+
free_fragment_list(patch->fragments);
29963002
patch->fragments = NULL;
29973003
}
29983004
} else {

0 commit comments

Comments
 (0)