POSIX requires malloc(), etc. to set ENOMEM on the failure, and e.g. BerkeleyDB relies on this: http://pubs.opengroup.org/onlinepubs/9699919799/functions/malloc.html This should fix confusing OSError exceptions with 0 error code when working with btree module.