use std::vector for managing temporary memory

This plugs a lot of potential memory leaks: if, in

```c++
double *p = new double[n];
double *q = new double[n];
```

the second allocation fails, the result of the first is not automatically cleaned up. With vectors, [the cleanup is automatic](https://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization).