On Mon, 10 Mar 2003, Steve Hay wrote:
> Hi,
>
> I have a memory leak problem in some XS code that populates a (passed
> in) hash with (newly created) hash references.
>
> Here is a sample XS routine and Perl wrapper which reproduces the problem:
>
> # XS
> void
> _fooxs(href)
> INPUT:
> HV *href;
>
> PREINIT:
> int i;
> int keylen;
> char key[6];
> HV *hash;
>
> PROTOTYPE: $
>
> CODE:
> for (i = 0; i < 100; i++) {
> hash = newHV();
> hv_store(hash, "string", 6, newSVpv("one", 3), 0);
> hv_store(hash, "number", 6, newSViv(1), 0);
> keylen = sprintf(key, "key%02d", i);
> hv_store(href, (const char *) key, keylen,
> newRV_noinc((SV *) hash), 0);
> }
>
> OUTPUT:
> href
^^^^^^^^
Not sure if this is the problem, but why are you declaring an output value
when the function does not return anything? Taking a close look at the
generated C code can be of help to see what might be going wrong.
Steve