apply: do not leak patches and fragments
commit6fe53908f954b5683ca08d3745be1d76dd665483
authorJared Hance <jaredhance@gmail.com>
Wed, 7 Mar 2012 22:21:25 +0000 (7 17:21 -0500)
committerJunio C Hamano <gitster@pobox.com>
Wed, 7 Mar 2012 22:56:08 +0000 (7 14:56 -0800)
treeecfb79acdac0385a6464d1c0ef9bcb314e4638bb
parente521850bfd4aa79632c99293a39dad56bcaa4143
apply: do not leak patches and fragments

In the while loop inside apply_patch, patch and fragments are
dynamically allocated with a calloc. However, only unused patches
are actually freed and the rest are left to leak. Since a list is
actively built up consisting of the used patches, they can simply be
iterated and freed at the end of the function.

In addition, the text in fragments were not freed, primarily because
they mostly point into a patch text that is freed as a whole. But
there are some cases where new piece of memory is allocated and
pointed by a fragment (namely, when handling a binary patch).

Introduce a free_patch bitfield to mark each fragment if its text
needs to be freed, and free patches, fragments and fragment text
that need to be freed when we are done with the input.

Signed-off-by: Jared Hance <jaredhance@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/apply.c