tree_print: check for NULL after allocating err