Backported malloc and realloc from avr-libc 1.8.0 (without test code)

Fix issues with tuning parameters and libraries that tries to estimate memory usage.

See #857