Ticket #395: fix_hint.patch

File fix_hint.patch, 1.3 KB (added by Vojtech Horky, 12 years ago)

Hint for fixing the memory allocator - reviewer wanted ;-)

  • uspace/lib/c/generic/malloc.c

    === modified file 'uspace/lib/c/generic/malloc.c'
     
    683683                return NULL;
    684684       
    685685        size_t falign = lcm(align, BASE_ALIGN);
    686         size_t real_size = GROSS_SIZE(ALIGN_UP(size, falign));
     686
     687        /*
     688         * This is minimal block size where we can allocate in.
     689         * The alignment is checked in malloc_area().
     690         */
     691        size_t real_size = GROSS_SIZE(size);
     692        /*
     693         * When growing the heap, we need to allocate at least this much
     694         * space.
     695         * Generally, to allocate x bytes aligned at y, we need at least
     696         * space x + y bytes.
     697         * Here we add some extra space (through ALIGN_UP(..., BASE_ALIGN))
     698         * just to be on the safe side.
     699         * Notice that we need to take care of all structures as growing
     700         * the heap might bring a new AS area.
     701         */
     702        size_t grow_size = ALIGN_UP(sizeof(heap_area_t), BASE_ALIGN)
     703            + ALIGN_UP(sizeof(heap_block_head_t), BASE_ALIGN)
     704            + falign
     705            + ALIGN_UP(size, BASE_ALIGN)
     706            + ALIGN_UP(sizeof(heap_block_foot_t), BASE_ALIGN);
    687707       
    688708        bool retry = false;
    689709        heap_block_head_t *split;
     
    716736       
    717737        if (!retry) {
    718738                /* Try to grow the heap space */
    719                 if (heap_grow(real_size)) {
     739                if (heap_grow(grow_size)) {
    720740                        retry = true;
    721741                        goto loop;
    722742                }