src/tio_malloc.c
/*
 * Add a newly allocated block to the list.
 */
Add a newly allocated block to the list.
Add a newly allocated block to the list .
static void list_alloc(const char subname[], const int line, void *p, const size_t size)
{
  size_t insp;
  if (NULL == p)  {
    return;
  }
  if (heap_error) {
    return;
  }
  if (disable) {
    return;
  }
  ++disable;
  if (heap_count < heap_limit) {
    insp = heap_count;
    ++heap_count;
  }
  else if (heap_holes > 0) {
    size_t i;
    for (i=0; i<heap_count; i++) {
      if (NULL == heap_list[i].p) {
        insp = i;
        --heap_holes;
        break;
      }
    }
  }
  else {
    size_t new_limit = heap_limit + heap_inc;
    size_t i;
    heap_list = (struct heap_data *)realloc(heap_list, (new_limit * sizeof(struct heap_data)));
    if (NULL == heap_list) {
      heap_count = 0;
      heap_limit = 0;
      heap_error = 1;
    }
    else {
      for (i=heap_limit; i<new_limit; ++i) {
#ifdef _TYPHIO_MEMORY_DEBUG
        (void) strcpy(heap_list[i].subname, " ");
        heap_list[i].line = 0;
#endif
        heap_list[i].p    = 0;
        heap_list[i].size = 0;
      }
      heap_limit = new_limit;
      insp = heap_count;
      ++heap_count;
    }
  }
#ifdef _TYPHIO_MEMORY_DEBUG
  (void) strncpy(heap_list[insp].subname, subname, SUBNAME_LEN);
  heap_list[insp].line = line;
#endif
  heap_list[insp].p    = p;
  heap_list[insp].size = size;
  memuse += size;
  if (memuse > maxmem) {
    maxmem = memuse;
  }
  ++memcount;
  if (memcount > maxcount) {
    maxcount = memcount;
  }
  summem += size;
  ++sumcount;
  if (add_exit) {
    atexit(exit_stats);
    add_exit = 0;
  }
  --disable;
  return;
}
static void list_alloc ( const char subname [ ] , const int line , void * p , const size_t size ) { size_t insp ; if ( NULL == p ) { return ; } if ( heap_error ) { return ; } if ( disable ) { return ; } ++ disable ; if ( heap_count < heap_limit ) { insp = heap_count ; ++ heap_count ; } else if ( heap_holes > 0 ) { size_t i ; for ( i = 0 ; i < heap_count ; i ++ ) { if ( NULL == heap_list [ i ] . p ) { insp = i ; -- heap_holes ; break ; } } } else { size_t new_limit = heap_limit + heap_inc ; size_t i ; heap_list = ( struct heap_data * ) realloc ( heap_list , ( new_limit * sizeof ( struct heap_data ) ) ) ; if ( NULL == heap_list ) { heap_count = 0 ; heap_limit = 0 ; heap_error = 1 ; } else { for ( i = heap_limit ; i < new_limit ; ++ i ) { #ifdef _TYPHIO_MEMORY_DEBUG ( void ) strcpy ( heap_list [ i ] . subname , " " ) ; heap_list [ i ] . line = 0 ; #endif heap_list [ i ] . p = 0 ; heap_list [ i ] . size = 0 ; } heap_limit = new_limit ; insp = heap_count ; ++ heap_count ; } } #ifdef _TYPHIO_MEMORY_DEBUG ( void ) strncpy ( heap_list [ insp ] . subname , subname , SUBNAME_LEN ) ; heap_list [ insp ] . line = line ; #endif heap_list [ insp ] . p = p ; heap_list [ insp ] . size = size ; memuse += size ; if ( memuse > maxmem ) { maxmem = memuse ; } ++ memcount ; if ( memcount > maxcount ) { maxcount = memcount ; } summem += size ; ++ sumcount ; if ( add_exit ) { atexit ( exit_stats ) ; add_exit = 0 ; } -- disable ; return ; }
Add a newly allocated block to the list.
Add a newly allocated block to the list .
/* Look for a empty slot in the list. */ /* Expand the list. */ /* Add the exit check if not already done so.  Allow for the
   * possibility that init() gets called many times. */