Re: help with memory leak

[email protected]
Newsgroups perl.xs
Message-ID <[email protected]>
Can't answer your leaking memory/reference count problem,
but please consider these points:

1. Generally when you iterate over a length, you want
     for (i = 0; i < len_data; ++i)   [not <=]

2. You're iterating i over the length of data.  Are
    you sure that odometer is long enough to support
    GETIV(odometer, i) ??

Best of luck,
cmac


On Jan 28, 2011, at 2:06 AM, Xavier Noria wrote:

> Hi, this C function is leaking memory:
>
> AV* __next_subset(SV* data_avptr, SV* odometer_avptr)
> {
>     AV* data     = GETAV(data_avptr);
>     AV* odometer = GETAV(odometer_avptr);
>     I32 len_data = av_len(data);
>     AV* subset   = newAV();
>     IV adjust    = 1;
>     int i;
>     IV n;
>
>     for (i = 0; i <= len_data; ++i) {
>         n = GETIV(odometer, i);
>         if (n) {
>             av_push(subset, newSVsv(*av_fetch(data, i, 0)));
>         }
>         if (adjust) {
>             adjust = 1 - n;
>             SETIV(odometer, i, adjust);
>         }
>     }
>
>     return subset;
> }
>
> I think the problem is the reference count of the AV*. Is that
> correct? How should I build/return it to prevent that?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.