builtin/commit: fix memory leak in `prepare_index()`
commitdd1055ed594f8fef18779cce3cd921c4ac66cf9c
authorMartin Ågren <martin.agren@gmail.com>
Fri, 22 Sep 2017 23:34:49 +0000 (23 01:34 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sun, 24 Sep 2017 01:05:45 +0000 (24 10:05 +0900)
tree7fe9a6fdbad0882ecfa07e1be9a19a69b5062b6a
parent94c9fd268d4287f6fbfef84793288479905a7e48
builtin/commit: fix memory leak in `prepare_index()`

Release `pathspec` and the string list `partial`.

When we clear the string list, make sure we do not free the `util`
pointers. That would result in double-freeing, since we set them up as
`item->util = item` in `list_paths()`.

Initialize the string list early, so that we can always release it. That
introduces some unnecessary overhead in various code paths, but means
there is one and only one way out of the function. If we ever accumulate
more things we need to free, it should be straightforward to do so.

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/commit.c