Reorder to avoid invalidated pointer reads.
Fix test to avoid passing pointers to transient objects to C.