Fix several memory leaks

When initializing an ndarray from a pointer, do not automatically set
the memory as foreign. Do it only if asked too, i.e. if the memory comes
from Python.