Win32: use low-level memory allocation during initialization
commite2b52a8ea8d47a448d0b8a042e07833001bf2183
authorKarsten Blees <blees@dcon.de>
Thu, 15 Mar 2012 19:29:04 +0000 (15 20:29 +0100)
committerPat Thoyts <patthoyts@users.sourceforge.net>
Mon, 1 Oct 2012 13:35:05 +0000 (1 14:35 +0100)
tree37bb831417ec9e6c44e6c467fdce0c3910618335
parent17eb945683b50cbf0f0101b92e25f7e4d240a131
Win32: use low-level memory allocation during initialization

As of d41489a6 "Add more large blob test cases", git's high-level memory
allocation functions (xmalloc, xmemdupz etc.) access the environment to
simulate limited memory in tests (see 'getenv("GIT_ALLOC_LIMIT")' in
memory_limit_check()). These functions should not be used before the
environment is fully initialized (particularly not to initialize the
environment itself).

The current solution ('environ = NULL; ALLOC_GROW(environ...)') only works
because MSVCRT's getenv() reinitializes environ when it is NULL (i.e. it
leaves us with two sets of unusabe (non-UTF-8) and unfreeable (CRT-
allocated) environments).

Add our own set of malloc-or-die functions to be used in startup code.

Also check the result of __wgetmainargs, which may fail if there's not
enough memory for wide-char arguments and environment.

This patch is in preparation of the sorted environment feature, which
completely replaces MSVCRT's getenv() implementation.

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