This problem seems to be a result of the SIGCHLD returning too quickly. The end result is that the array of %childs doesn't get emptied as 2 or more SIGCHLD's are received too quickly for more then one PID to be removed from the list.
A simple fix is to slow down the children in the test such that the parent can flush them. Just add a "sleep 1;" at the bottom of the for loop which spawns the children. That gives enough separation on death to allow the parent to reap them.