this is my sample xs code, which calls the C++ class to fetch details
of the person. The code works fine, i have couple of questions on
this, which would help me in identifying mem leaks with this piece of
code:

1. Should a "CLEANUP" tag be added which cleans up the array
( av_clear; av_undef;)?

2. Is the way hv is handled in the loop appropriate? Will it get
cleaned up appropriately?

 thanks.

==============================
AV *
perlWrapPers::GetDetails(name = NULL)
INPUT:
        char * name
PREINIT:
        AV *av;
        HV *hv;
        int size, i;
        pdetails_vector pv;
        int vect;
CODE:
        THIS->GetDetails(name,&pv);
        av =  (AV*)sv_2mortal((SV*)newAV());
        size = pv.size();
        for(i=0; i<size; i++) {
                struct pdetails *pd;
                char *args;
                hv = newHV();
                pd = pv[i];
                hv_store(hv, "name", 4, newSVpv(pd->name, strlen(pd->name)),
0);
                hv_store(hv, "age", 3, newSVuv(pd->pid), 0);
                av_push(av, newRV((SV *)hv));
        }
        for (vect = 0; vect < pv.size(); vect++)
        delete pv[vect];
        pv.clear();

        RETVAL = av;
OUTPUT:
        RETVAL
==============================

Reply via email to