keep stacks in vector<> and use them LIFO

reduced malloc count, reduced cache pressure, fixed very unlikely fd leak