Fix memory leak

Make AsInvocation not be a pointer, completing changes from 8b82a4ccf1cbb486587291ab9275f883cd9fe0be.