I had the same problem when I returned an AV *. You have to use the sv_2mortal macro in order to have the correct ref count.
AV * subset = (AV *)sv_2mortal((SV *)newAV()); > I think the problem is the reference count of the AV*. Is that > correct? How should I build/return it to prevent that? > AV* subset = newAV();