fix memory leak on pop/shift