read_gitfile_gently: fix use-after-free
commit38ae8784074852c8e7b651f4f6e44e07466da7e1
authorJeff King <peff@peff.net>
Fri, 26 Jun 2015 09:03:31 +0000 (26 05:03 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 26 Jun 2015 16:23:08 +0000 (26 09:23 -0700)
tree44ca3f69a322f6019126661e2f3714f10efec71a
parent0179ca7a626e0a6c7bf5eaccf88dead307306dee
read_gitfile_gently: fix use-after-free

The "dir" variable is a pointer into the "buf" array. When
we hit the cleanup_return path, the first thing we do is
free(buf); but one of the error messages prints "dir", which
will access the memory after the free.

We can fix this by reorganizing the error path a little. We
act on the fatal, error-printing conditions first, as they
want to access memory and do not care about freeing. Then we
free any memory, and finally return.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
setup.c