On Thursday 05 April 2007 16:56, Mehmet Yavuz Selim Soyturk wrote:

> The next program causes a memory leak for me.
>
> .sub main :main
> loop:
>     $P0 = new .String
>     goto loop
> .end
>
>
> Interestingly, no memory leak with:
>
> .sub main :main
> loop:
>         $S0 = "foo"
>         $P0 = new .String
>         goto loop
> .end

I can't explain that, but here's some suspicious code in 
Parrot_allocate_string() in src/resources.c:

    new_size = aligned_string_size(str, size);
    mem      = (char *)mem_allocate(interp, new_size, pool);
    mem     += sizeof (void*);

    PObj_bufstart(str) =  str->strstart = mem;
    PObj_buflen(str)   = new_size - sizeof (void*);

If I identify and read the related freeing code correctly (Parrot_dod_sweep() 
in src/gc/dod.c):

                else if (PObj_sysmem_TEST(b) && PObj_bufstart(b)) {
                    /* has sysmem allocated, e.g. string_pin */
                    mem_sys_free(PObj_bufstart(b));
                    PObj_bufstart(b) = NULL;
                    PObj_buflen(b)   = 0;
                }

... then there's a leak the sizeof (void *).

I don't guarantee that I've identified the appropriate code clearly though; 
digging through this is tricky.

Does this sound familiar or interesting or fun to anyone else?

-- c

Reply via email to