Core: guard against failed allocation during binary upgrade.

Patch by Piotr Sikora.