Branch: Tag:

2014-10-04

2014-10-04 11:35:21 by Arne Goedeke <el@laramies.com>

block_allocator: use Valgrind macros in the right order

When sorting the free list during ba_walk(), the Valgrind macros were
used in the wrong order. This led to spurious Valgrind warnings.

468:    */    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);
503:    * 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;    }   
517:    */       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);