Win32: fix environment memory leaks
commit10e1987472f77ba1748f325ca0943b5599ddf498
authorKarsten Blees <blees@dcon.de>
Fri, 25 Nov 2011 20:29:40 +0000 (25 21:29 +0100)
committerStepan Kasal <kasal@ucw.cz>
Thu, 29 May 2014 08:40:14 +0000 (29 10:40 +0200)
treed5f6e7594b6ebc9f7661d2ecdd4a62ec6f7bfb46
parent50cd6154917ad4dda6290cb056f16dd5971b7c39
Win32: fix environment memory leaks

All functions that modify the environment have memory leaks.

Disable gitunsetenv in the Makefile and use env_setenv (via mingw_putenv)
instead (this frees removed environment entries).

Move xstrdup from env_setenv to make_augmented_environ, so that
mingw_putenv no longer copies the environment entries (according to POSIX
[1], "the string [...] shall become part of the environment"). This also
fixes the memory leak in gitsetenv, which expects a POSIX compliant putenv.

[1] http://pubs.opengroup.org/onlinepubs/009695399/functions/putenv.html

Note: This patch depends on taking control of char **environ and having
our own mingw_putenv (both introduced in "Win32: Unicode environment
(incoming)").

Signed-off-by: Karsten Blees <blees@dcon.de>
compat/mingw.c
compat/mingw.h
config.mak.uname