build: tasks: Add some protection to out of memory

Signed-off-by: Bart Kuivenhoven <bemkuivenhoven@gmail.com>