pike.git / src / block_allocator.c

version» Context lines:

pike.git/src/block_allocator.c:66:    p->h.first = BA_BLOCKN(*l, p, 0);    PIKE_MEMPOOL_ALLOC(a, p->h.first, l->block_size);    p->h.first->next = BA_ONE;    PIKE_MEMPOOL_FREE(a, p->h.first, l->block_size);   }      static struct ba_page * ba_alloc_page(struct block_allocator * a, int i) {    struct ba_layout l = ba_get_layout(a, i);    size_t n = l.offset + l.block_size + l.doffset;    struct ba_page * p; +  +  /* +  * note that i is always positive, so this only +  * happens if ba_get_layout overflows +  */ +  if (a->l.offset > l.offset || n < l.offset) { +  Pike_error("Overflow.\n"); +  } +     if (l.alignment) {    p = xalloc_aligned(n, l.alignment);    } else {   #ifdef DEBUG_MALLOC    /* In debug malloc mode, calling xalloc from the block alloc may result    * in a deadlock, since xalloc will call ba_alloc, which in turn may call xalloc.    */    p = system_malloc(n);    if (!p) {    fprintf(stderr, "Fatal: Out of memory.\n");
pike.git/src/block_allocator.c:122:    if (a->l.alignment) {    if (a->l.alignment & (a->l.alignment - 1))    Pike_fatal("Block allocator a->l.alignment is not a power of 2.\n");    if (block_size & (a->l.alignment-1))    Pike_fatal("Block allocator block size is not aligned.\n");    a->l.doffset = PIKE_ALIGNTO(sizeof(struct ba_page), a->l.alignment);    } else {    a->l.doffset = sizeof(struct ba_page);    }    -  if (a->l.blocks & (a->l.blocks - 1)) -  a->l.blocks = round_up32(a->l.blocks); +  if (a->l.blocks & (a->l.blocks - 1)) { +  unsigned INT32 tmp = round_up32(a->l.blocks); +  if (tmp) a->l.blocks = tmp; +  } else if (!a->l.blocks) a->l.blocks = 1;    a->l.block_size = block_size;    a->l.offset = block_size * (a->l.blocks-1);   }      PMOD_EXPORT void ba_init_aligned(struct block_allocator * a, unsigned INT32 block_size,    unsigned INT32 blocks, unsigned INT32 alignment) {    a->l.blocks = blocks;    a->l.block_size = block_size;    a->l.alignment = alignment;    ba_low_init_aligned(a);
pike.git/src/block_allocator.c:215:    for (i = a->size - 1; i >= 0; i--) {    struct ba_page * p = a->pages[i];       if (p->h.first) {    a->alloc = i;    return;    }    }       if (a->size == (sizeof(a->pages)/sizeof(a->pages[0]))) { -  Pike_error("Out of memory."); +  Pike_error("Out of memory.\n");    }    a->pages[a->size] = ba_alloc_page(a, a->size);    a->alloc = a->size;    a->size++;   }      ATTRIBUTE((malloc))   PMOD_EXPORT void * ba_alloc(struct block_allocator * a) {    struct ba_page * p = a->pages[a->alloc];    struct ba_block_header * ptr;