Check for failed allocations. Spotted by Martin Bealby.