hash: avoid memory leak on allocation failure