IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 39415


Ignore:
Timestamp:
Feb 28, 2016, 5:44:25 AM (10 years ago)
Author:
eugene
Message:

add a realloc counter to the memblock (in dummy slot); test realloc did not mess up endblocks

Location:
branches/eam_branches/ohana.20160226/src/libohana
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20160226/src/libohana/include/ohana_allocate.h

    r39324 r39415  
    1313  int line;                   // line (re)allocated
    1414  int freed;                  // memory has been freed
    15   int dummy;                  // need to put endblock on the endpost
     15  int Nalloc;                 // need to put endblock on the endpost
    1616  uint32_t endblock;          // endpost marker
    1717} OhanaMemblock;
  • branches/eam_branches/ohana.20160226/src/libohana/src/ohana_allocate.c

    r39409 r39415  
    5555  Nelem = MAX (1, Nelem);
    5656  size = Nelem * esize;
     57  // if (size % 8) size += (8 - size % 8); // do NOT round to 8-byte boundary (did not fix corruption)
    5758
    5859  // total size is : memblock + data + endpost
     
    7576  new->func = func;
    7677  new->freed = FALSE;
     78  new->Nalloc = 1;
    7779
    7880  // poison the whole memory: we should not rely of 0'ed memory
     
    129131  Nelem = MAX (1, Nelem);
    130132  size = Nelem * esize;
     133  // if (size % 8) size += (8 - size % 8); // do NOT round to 8-byte boundary (did not fix corruption)
    131134
    132135  // requested same size as current allocation
     
    134137    return in;
    135138  }
     139  size_t oldsize = old->size;
    136140
    137141  pthread_mutex_lock(&memBlockListMutex);
     
    156160  new->nextBlock = old->nextBlock;
    157161  new->prevBlock = old->prevBlock;
     162  new->startblock = OHANA_MEMMAGIC;
     163  new->endblock = OHANA_MEMMAGIC;
     164  new->freed = FALSE;
    158165# else
    159166  // ask for new memory
     
    164171# endif
    165172 
    166   // set the end-post values
    167   new->startblock = OHANA_MEMMAGIC;
    168   new->endblock = OHANA_MEMMAGIC;
    169   *(uint32_t *)(ptr_new + size) = OHANA_MEMMAGIC;
     173  if (new->startblock != OHANA_MEMMAGIC) ohana_memabort ("corrupt memory (%s, %d, %s)\n", file, line, func);
     174  if (new->endblock != OHANA_MEMMAGIC) ohana_memabort ("corrupt memory (%s, %d, %s)\n", file, line, func);
    170175
    171176  // set the memory metadata
     
    174179  new->line = line;
    175180  new->func = func;
    176   new->freed = FALSE;
    177 
    178   // update the endpost (the others were set originally
     181  new->Nalloc++;
     182
     183  // update the endpost (the others were set originally and maintained through the realloc)
    179184  *(uint32_t *)(ptr_new + size) = OHANA_MEMMAGIC;
     185
     186  // poison the new memory: we should not rely of 0'ed memory
     187  if (new->size > oldsize) {
     188    memset (&ptr_new[oldsize], 0x7f, new->size - oldsize);
     189  }
    180190
    181191  // need to reset lastBlock in case we moved
Note: See TracChangeset for help on using the changeset viewer.