BUG: fix missing check for memory allocation failure in ufuncs

closes gh-4018
Merge pull request #4020 from juliantaylor/memcrash

BUG: fix missing check for memory allocation failure in ufuncs