Fix the massive memory leaks in frame allocation

Change most ptw_frame functions so that they take an additional output frame
pointer as an argument rather than allocating a new one each time.  Makes it
easier to keep track and free frames which need freeing, so we don't leak 160KB
of memory every time we call a function.