Avoid a null-pointer dereference in _tri.cpp

Found using the clang static analyzer:
if PyArray_ContiguousFromObject returns NULL,
PyArray_NDIM(x) causes a null-pointer dereference.
Initialize the states array with calloc in _macosx.m

To silence a warning about garbage data from the clang
static analyzer. Also check the calloc return value.
Release some unreleased objects in the macosx backend
Merge pull request #2994 from jkseppan/macosx-fixes

Minor fixes in _macosx.m
Merge pull request #2993 from jkseppan/tri-null-pointer

Avoid a null-pointer dereference in _tri.cpp