diskutil eraseDisk results in Error: 12: POSIX reports: Cannot allocate memory
It could be likely that you are not running the command as admin (Unix root) user.

To run a command with administrator privileges use the sudo command so:

$ sudo diskutil eraseDisk JHFS+ UntitledUFS disk1


The error message can lead one astray giving the impression that something else is wrong but it is likely a permissions issue.