commit: copy saved getenv() result
commit406bab3811a220400da6a43da71346cbfc466fc9
authorJeff King <peff@peff.net>
Fri, 11 Jan 2019 22:15:40 +0000 (11 17:15 -0500)
committerJunio C Hamano <gitster@pobox.com>
Sat, 12 Jan 2019 02:48:58 +0000 (11 18:48 -0800)
tree6eb74c00852373ca1e069a9541f4c19e26b12fa1
parent8aac69038fa6c5f957559ca7e08a5e2e8f74d0fa
commit: copy saved getenv() result

We save the result of $GIT_INDEX_FILE so that we can restore it after
setting it to a new value and running add--interactive. However, the
pointer returned by getenv() is not guaranteed to be valid after calling
setenv(). This _usually_ works fine, but can fail if libc needs to
reallocate the environment block during the setenv().

Let's just duplicate the string, so we know that it remains valid.

In the long run it may be more robust to teach interactive_add() to take
a set of environment variables to pass along to run-command when it
execs add--interactive. And then we would not have to do this
save/restore dance at all. But this is an easy fix in the meantime.

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