HV *hash = (HV *)sv_2mortal((SV *) newHV()); SV *type = newSVpv("string", 0); //SV *type = sv_2mortal(newSVpv("string", 0)); SvREFCNT_inc( type ); if ( NULL == hv_store( hash, "type", strlen("type"), type, 0) ) { SvREFCNT_dec( type ); printf("hv_store failed\n"); exit(1); } XPUSHs(sv_2mortal(newRV((SV *)hash)));