hash: fix out-of-memory handling in hash creation