Win32: fix environment memory leaks
commit8cb05bdbe4be52e36426e7de0ed7b661c081950c
authorKarsten Blees <blees@dcon.de>
Fri, 25 Nov 2011 20:29:40 +0000 (25 21:29 +0100)
committerJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 3 May 2012 16:09:53 +0000 (3 11:09 -0500)
tree6f67ecce61e99eafc55e90f5ab40b3a01f0e5dda
parent91eb00d3a9f907be9478e17644f54415f430ace6
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