unsigned long oldpos, oldlines;
unsigned long newpos, newlines;
const char *patch;
+ unsigned free_patch:1,
+ rejected:1;
int size;
- int rejected;
int linenr;
struct fragment *next;
};
struct patch *next;
};
+static void free_patch(struct patch *patch)
+{
+ while (patch) {
+ struct patch *patch_next = patch->next;
+ struct fragment *fragment = patch->fragments;
+
+ while (fragment) {
+ struct fragment *fragment_next = fragment->next;
+ if (fragment->patch != NULL && fragment->free_patch)
+ free((char *)fragment->patch);
+ free(fragment);
+ fragment = fragment_next;
+ }
+ free(patch);
+ patch = patch_next;
+ }
+}
+
/*
* A line in a file, len-bytes long (includes the terminating LF,
* except for an incomplete line at the end if the file ends with
frag = xcalloc(1, sizeof(*frag));
frag->patch = inflate_it(data, hunk_size, origlen);
+ frag->free_patch = 1;
if (!frag->patch)
goto corrupt;
free(data);
struct patch *list = NULL, **listp = &list;
int skipped_patch = 0;
- /* FIXME - memory leak when using multiple patch files as inputs */
memset(&fn_table, 0, sizeof(struct string_list));
patch_input_file = filename;
read_patch_file(&buf, fd);
listp = &patch->next;
}
else {
- /* perhaps free it a bit better? */
- free(patch);
+ free_patch(patch);
skipped_patch++;
}
offset += nr;
if (summary)
summary_patch_list(list);
+ free_patch(list);
strbuf_release(&buf);
return 0;
}