FIX MemoryError raising in trees (+test)

I got this wrong all along: Cython functions that don't return Python
objects need an "except" clause to actually propagate exceptions (spotted
by @GaelVaroquaux, @arjoly).

Simplified memory management and unified error messages by safe_realloc.