task 5: heap overflow when sending msg in the last iteration