Git Extensions: Win32 error 487: Couldn't reserve space for cygwin's heap, Win32 error 0
Git Extensions: Everything was working fine until yesterday.
But suddenly I am get this error when I try to pull some repositories using git extensions
C:\Program Files\Git\bin\git.exe pull --progress "origin"
Done
0 [main] us 0 init_cheap: VirtualAlloc pointer is null, Win32 error 487
AllocationBase 0x0, BaseAddress 0x68560000, RegionSize 0x390000, State 0x10000
C:\Program Files\Git\bin\sh.exe: *** Couldn't reserve space for cygwin's heap, Win32 error 0
It is happening for all the repositories which I have cloned. But, my git bash is working fine. I don't have any idea what is going on. Any idea as to why this is happening?
Solution 1:
I had the same problem. I found solution here http://jakob.engbloms.se/archives/1403
c:\msysgit\bin>rebase.exe -b 0x50000000 msys-1.0.dll
For me solution was slightly different. It was
C:\Program Files (x86)\Git\bin>rebase.exe -b 0x50000000 msys-1.0.dll
Before you rebase dlls, you should make sure it is not in use:
tasklist /m msys-1.0.dll
And make a backup:
copy msys-1.0.dll msys-1.0.dll.bak
If the rebase command fails with something like:
ReBaseImage (msys-1.0.dll) failed with last error = 6
You will need to perform the following steps in order:
- Copy the dll to another directory
- Rebase the copy using the commands above
- Replace the original dll with the copy.
If any issue run the commands as Administrator
Solution 2:
Cygwin uses persistent shared memory sections, which can on occasion become corrupted. The symptom of this is that some Cygwin programs begin to fail, but other applications are unaffected. Since these shared memory sections are persistent, often a system reboot is needed to clear them out before the problem can be resolved.
Solution 3:
tl;dr: Install 64-bit Git for Windows 2.
Technical details
0 [main] us 0 init_cheap: VirtualAlloc pointer is null, Win32 error 487
AllocationBase 0x0, BaseAddress 0x68570000, RegionSize 0x2A0000, State 0x10000
PortableGit\bin\bash.exe: *** Couldn't reserve space for cygwin's heap, Win32 error 0
This symptom by itself has nothing to do with image bases of executables, corrupted Cygwin's shared memory sections, conflicting versions of DLLs etc.
It's Cygwin code failing to allocate a ~5 MB large chunk of memory for its heap at this fixed address 0x68570000, while only a hole ~2.5 MB large was apparently available there. The relevant code can be seen in msysgit source.
Why is that part of address space not free?
There can be many reasons. In my case it was some other modules loaded at a conflicting address:
The last address would be around 0x68570000 + 5 MB = 0x68C50000, but there are these WOW64-related DLLs loaded from 0x68810000 upwards, which block the allocation.
Whenever there is some shared DLL, Windows in general tries to load it at the same virtual address in all processes to save some relocation processing. It's just a matter of bad luck that these system components got somehow loaded at a conflicting address this time.
Why is there Cygwin in your Git?
Because Git is a rich suite consisting of some low level commands and a lot of helpful utilities, and mostly developed on Unix-like systems. In order to be able to build it and run it without massive rewriting, it need at least a partial Unix-like environment.
To accomplish that, people have invented MinGW and MSYS - a minimal set of build tools to develop programs on Windows in an Unix-like fashion. MSYS also contains a shared library, this msys-1.0.dll
, which helps with some of the compatibility issues between the two platforms during runtime. And many parts of that have been taken from Cygwin, because someone already had to solve the same problems there.
So it's not Cygwin, it's MinGW's runtime DLL what's behaving weird here.
In Cygwin, this code has actually changed a lot since what's in MSYS 1.0 - the last commit message for that file says "Import Cygwin 1.3.4", which is from 2001!
Both current Cygwin and the new version of MSYS - MSYS2 - already have different logic in place, which is hopefully more robust. It's only old versions of Git for Windows which have been still built using the old broken MSYS system.
Clean solutions:
- Install Git for Windows 2 - it is built with the new, properly maintained MSYS2 and also has many new features, plenty of bug fixes, security improvements and so on. If at all possible, it is also recommended to use the 64-bit version. But the rebase workaround is performed automatically behind the scenes for 32-bit systems, so the chances of the problem happening there should be lower too.
- Simply restarting the computer to clean the address space (loading these modules at a different random address) might work, but really, just upgrade to Git for Windows 2 to get the security fixes if nothing else.
Hacky solutions:
- Changing
PATH
can sometimes work because there might be different versions ofmsys-1.0.dll
in different versions of Git or other MSYS-based applications, which perhaps use different address, different size of this heap etc. - Rebasing
msys-1.0.dll
might be a waste of time, because 1) being a DLL, it already has relocation information and 2) "in any version of Windows OS there is no guarantee that a (...) DLL will always load at same address space" anyway (source). The only way this can help is if themsys-1.0.dll
itself loads at the conflicting address it's then trying to use. Apparently that's the case sometimes, as this is what the Git for Windows guys are doing automatically on 32-bit systems. - Considering the findings above, I originally binary patched the
msys-1.0.dll
binary to use a different value for_cygheap_start
and that resolved the problem immediately.
Solution 4:
Very simple verison of the rebase solution:
Go to the folder where git is installed, such as:
C:\Program Files (x86)\Git\bin
By holding shift and right clicking in the folder, you should be able to open a command prompt as administrator from there (thanks to https://stackoverflow.com/users/355389/darren-lewis for that comment),
Then run:
rebase.exe -b 0x50000000 msys-1.0.dll
This fixed it for me when the restart approach didn't work.
Hope it helps.
Solution 5:
I have seen the same error message after upgrading to git1.8.5.2:
Simply make a search for all msys-1.0.dll
on your C:\
drive, and make the one used by Git comes first.
For instance, in my case I simply changed the order of:
C:\prgs\Gow\Gow-0.7.0\bin\msys-1.0.dll
C:\prgs\git\PortableGit-1.8.5.2-preview20131230\bin\msys-1.0.dll
By making the Git path C:\prgs\git\PortableGit-1.8.5.2-preview20131230\bin\
come first in my %PATH%
, the error message disappeared.
No need to reboot or to even change the DOS session.
Once the %PATH%
is updated in that DOS session, the git commands just work.
Note that carmbrester and Sixto Saez both report below (in the comments) having to reboot in order to fix the issue.
Note: First, also removing any msys-1.0.dll
, like one in %LOCALAPPDATA%