use ALLOCA_N to prevent memory leak on exception