pike.git / src / block_allocator.c

version» Context lines:

pike.git/src/block_allocator.c:461:    /* we should probably reuse an area for this.    */    bv_set_vector(&v, alloca(i));    memset(v.v, 0, i);       /*    * store the position of all blocks in a bitmask    */    while (b) {    unsigned INT32 n = ba_block_number(l, p, b); + #ifdef PIKE_DEBUG +  if (bv_get(&v, n)) { +  fprintf(stderr, "Double free detected."); +  /* Printing an error to stderr here and continuing makes probably more sense +  * than throwing an error. This sort algorithm will "correct" the corrupted free +  * list. +  */ +  } + #endif    bv_set(&v, n, 1);    j++;    PIKE_MEMPOOL_ALLOC(a, b, l->block_size);    PIKE_MEM_RW_RANGE(b, sizeof(struct ba_block_header));    if (b->next == BA_ONE) {    v.length = n+1;    PIKE_MEMPOOL_FREE(a, b, l->block_size);    break;    } else {    struct ba_block_header * tmp = b->next;
pike.git/src/block_allocator.c:496:    }       if (!j) goto last;       j = 0;       /*    * We now rechain all blocks.    */    while ((i = bv_ctz(&v, j)) != (size_t)-1) { -  *t = BA_BLOCKN(*l, p, i); -  if (b) PIKE_MEMPOOL_FREE(a, b, l->block_size); -  b = *t; +  struct ba_block_header * tmp = b; +  *t = b = BA_BLOCKN(*l, p, i); +  if (tmp) PIKE_MEMPOOL_FREE(a, tmp, l->block_size);    PIKE_MEMPOOL_ALLOC(a, b, l->block_size); -  t = &((*t)->next); +  t = &(b->next);    j = i+1;    }      last:    /*    * The last one    */       if (v.length < l->blocks) { -  if (b) PIKE_MEMPOOL_FREE(a, b, l->block_size); +  struct ba_block_header * tmp = b;    *t = b = BA_BLOCKN(*l, p, v.length); -  +  if (tmp) PIKE_MEMPOOL_FREE(a, tmp, l->block_size);    PIKE_MEMPOOL_ALLOC(a, b, l->block_size); -  (*t)->next = BA_ONE; +  b->next = BA_ONE;    PIKE_MEMPOOL_FREE(a, b, l->block_size);    } else {    if (b) PIKE_MEMPOOL_FREE(a, b, l->block_size);    PIKE_MEMPOOL_ALLOC(a, t, l->block_size);    *t = NULL;    PIKE_MEMPOOL_FREE(a, t, l->block_size);    }      }