Return error if allocation of new element was not possible.

Found by Coverity.