I recently encountered the same problem and fixed it with the modification on _sbrk in syscall.c shown above.
This topic is quite old. But CubeMX still generates this faulty syscall.c when RTOS is used.
By the way, this effect is also responsible for printf float creating a hard fault when using with -u _printf_float and RTOS.
Im am using CubeMX 5.4.0 on a STM32L4R7Z