Win32: fix environment memory leaks
commit58e6059f600891fba1ba8b3f7030912e9c08c0c3
authorKarsten Blees <blees@dcon.de>
Fri, 25 Nov 2011 20:29:40 +0000 (25 21:29 +0100)
committerErik Faye-Lund <kusmabite@gmail.com>
Fri, 4 Jan 2013 14:57:07 +0000 (4 15:57 +0100)
tree0620d2e1b4d9264db2e24e593b67787695713a65
parent6d87a4117e9ebf93b243e8b5df84944ea121af18
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>
Makefile
compat/mingw.c
compat/mingw.h