help with memory leak
[email protected] (Xavier Noria)
| Newsgroups | perl.xs |
|---|---|
| Message-ID | <[email protected]> |
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?