Core: fixed resource leak if binary upgrade fails due to no memory.

Found by Coverity (CID 992320).