Commit 6fe5390
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>1 parent e521850 commit 6fe5390
1 file changed
+23
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
| 156 | + | |
155 | 157 | | |
156 | | - | |
157 | 158 | | |
158 | 159 | | |
159 | 160 | | |
| |||
195 | 196 | | |
196 | 197 | | |
197 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
198 | 217 | | |
199 | 218 | | |
200 | 219 | | |
| |||
1741 | 1760 | | |
1742 | 1761 | | |
1743 | 1762 | | |
| 1763 | + | |
1744 | 1764 | | |
1745 | 1765 | | |
1746 | 1766 | | |
| |||
3686 | 3706 | | |
3687 | 3707 | | |
3688 | 3708 | | |
3689 | | - | |
3690 | 3709 | | |
3691 | 3710 | | |
3692 | 3711 | | |
| |||
3711 | 3730 | | |
3712 | 3731 | | |
3713 | 3732 | | |
3714 | | - | |
3715 | | - | |
| 3733 | + | |
3716 | 3734 | | |
3717 | 3735 | | |
3718 | 3736 | | |
| |||
3753 | 3771 | | |
3754 | 3772 | | |
3755 | 3773 | | |
| 3774 | + | |
3756 | 3775 | | |
3757 | 3776 | | |
3758 | 3777 | | |
| |||
0 commit comments