Fixed segfaults due to stack variables being deallocated.

Array structures were being allocated on the stack and their address given
as return values. The structures were being deallocated when the stack
frame moved. Also fixed a bug where Deallocated was freeing the wrong
array.