Malloc failure

The call to malloc may fail if enough memory is not available. This catches the error and raises a RuntimeError, rather than segfaulting.