Print this page
new smatch


  86          */
  87         if (desc->freelist) {
  88                 void **p = desc->freelist;
  89                 retval = p;
  90                 desc->freelist = *p;
  91                 do {
  92                         *p = NULL;
  93                         p++;
  94                 } while ((size -= sizeof(void *)) > 0);
  95                 return retval;
  96         }
  97 
  98         desc->allocations++;
  99         desc->useful_bytes += size;
 100         size = (size + alignment - 1) & ~(alignment-1);
 101         if (!blob || blob->left < size) {
 102                 unsigned int offset, chunking = desc->chunking;
 103                 struct allocation_blob *newblob = blob_alloc(chunking);
 104                 if (!newblob)
 105                         die("out of memory");


 106                 desc->total_bytes += chunking;
 107                 newblob->next = blob;
 108                 blob = newblob;
 109                 desc->blobs = newblob;
 110                 offset = offsetof(struct allocation_blob, data);
 111                 offset = (offset + alignment - 1) & ~(alignment-1);
 112                 blob->left = chunking - offset;
 113                 blob->offset = offset - offsetof(struct allocation_blob, data);
 114         }
 115         retval = blob->data + blob->offset;
 116         blob->offset += size;
 117         blob->left -= size;
 118         return retval;
 119 }
 120 
 121 void show_allocations(struct allocator_struct *x)
 122 {
 123         fprintf(stderr, "%s: %lu allocations, %lu bytes (%lu total bytes, "
 124                         "%6.2f%% usage, %6.2f average size)\n",
 125                 x->name, x->allocations, x->useful_bytes, x->total_bytes,




  86          */
  87         if (desc->freelist) {
  88                 void **p = desc->freelist;
  89                 retval = p;
  90                 desc->freelist = *p;
  91                 do {
  92                         *p = NULL;
  93                         p++;
  94                 } while ((size -= sizeof(void *)) > 0);
  95                 return retval;
  96         }
  97 
  98         desc->allocations++;
  99         desc->useful_bytes += size;
 100         size = (size + alignment - 1) & ~(alignment-1);
 101         if (!blob || blob->left < size) {
 102                 unsigned int offset, chunking = desc->chunking;
 103                 struct allocation_blob *newblob = blob_alloc(chunking);
 104                 if (!newblob)
 105                         die("out of memory");
 106                 if (size > chunking)
 107                         die("alloc too big");
 108                 desc->total_bytes += chunking;
 109                 newblob->next = blob;
 110                 blob = newblob;
 111                 desc->blobs = newblob;
 112                 offset = offsetof(struct allocation_blob, data);
 113                 offset = (offset + alignment - 1) & ~(alignment-1);
 114                 blob->left = chunking - offset;
 115                 blob->offset = offset - offsetof(struct allocation_blob, data);
 116         }
 117         retval = blob->data + blob->offset;
 118         blob->offset += size;
 119         blob->left -= size;
 120         return retval;
 121 }
 122 
 123 void show_allocations(struct allocator_struct *x)
 124 {
 125         fprintf(stderr, "%s: %lu allocations, %lu bytes (%lu total bytes, "
 126                         "%6.2f%% usage, %6.2f average size)\n",
 127                 x->name, x->allocations, x->useful_bytes, x->total_bytes,