Re: [PATCH 07/15] merge-recursive: fix memleaks
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 21, 2015, 03:48 UTC
- Message-ID
- <xmqqoannau4h.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <1426897692-18322-8-git-send-email-sbeller@google.com>
Stefan Beller <sbeller@google.com> writes:
Show 11 quoted lines
> Usually when using string lists it looks like: > struct string_list a = STRING_LIST_INIT_NODUP; > // do stuff with a such as > string_list_insert(&a, "test string"); > print_string_list(&a, "test prefix"); > // Cleaning up works on everything inside the struct, not on the > // struct itself: > string_list_clear(&a); > > But as we deal with the pointers to the string lists directly, we also > need to free the actual struct.
In other words, these two were allocated for the sole use of this fuction by get_renames(), so this function is responsible for freeing it?
Sounds sensible.
Show 19 quoted lines
> Signed-off-by: Stefan Beller <sbeller@google.com> > --- > merge-recursive.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/merge-recursive.c b/merge-recursive.c > index 771f5e2..1c9c30d 100644 > --- a/merge-recursive.c > +++ b/merge-recursive.c > @@ -1858,6 +1858,9 @@ int merge_trees(struct merge_options *o, > string_list_clear(re_head, 0); > string_list_clear(entries, 1); > > + free(re_merge); > + free(re_head); > + free(entries); > } > else > clean = 1;