malloc won't allocate the last 4KB of available heap (addresses in 2003F000- 20040000). A simple test program is here: https://gist.github.com/MichaelBell/a13513a483a07a41c5b74e8458fba51d
I believe the problem is _sbrk should allow heap_end to be moved up to __StackLimit. I've got a commit which appears to fix the issue but I'm not sufficiently familiar with how this is meant to work to know whether that's the correct approach.