MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / _free

Method _free

libCacheSim/dataStructure/sparsepp/spp_dlalloc.h:3123–3227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3121/* ---------------------------- free --------------------------- */
3122
3123void malloc_state::_free(mchunkptr p)
3124{
3125 if (1)
3126 {
3127 check_inuse_chunk(p);
3128 if (rtcheck(ok_address(p) && ok_inuse(p)))
3129 {
3130 size_t psize = p->chunksize();
3131 mchunkptr next = (mchunkptr)p->chunk_plus_offset(psize);
3132 if (!p->pinuse())
3133 {
3134 size_t prevsize = p->_prev_foot;
3135 if (p->is_mmapped())
3136 {
3137 psize += prevsize + SPP_MMAP_FOOT_PAD;
3138 if (SPP_CALL_MUNMAP((char*)p - prevsize, psize) == 0)
3139 _footprint -= psize;
3140 goto postaction;
3141 }
3142 else
3143 {
3144 mchunkptr prev = (mchunkptr)p->chunk_minus_offset(prevsize);
3145 psize += prevsize;
3146 p = prev;
3147 if (rtcheck(ok_address(prev)))
3148 {
3149 // consolidate backward
3150 if (p != _dv)
3151 unlink_chunk(p, prevsize);
3152 else if ((next->_head & INUSE_BITS) == INUSE_BITS)
3153 {
3154 _dvsize = psize;
3155 p->set_free_with_pinuse(psize, next);
3156 goto postaction;
3157 }
3158 }
3159 else
3160 goto erroraction;
3161 }
3162 }
3163
3164 if (rtcheck(ok_next(p, next) && ok_pinuse(next)))
3165 {
3166 if (!next->cinuse())
3167 {
3168 // consolidate forward
3169 if (next == _top)
3170 {
3171 size_t tsize = _topsize += psize;
3172 _top = p;
3173 p->_head = tsize | PINUSE_BIT;
3174 if (p == _dv)
3175 {
3176 _dv = 0;
3177 _dvsize = 0;
3178 }
3179 if (should_trim(tsize))
3180 sys_trim(0);

Callers 1

mspace_freeFunction · 0.80

Calls 8

chunksizeMethod · 0.80
chunk_plus_offsetMethod · 0.80
pinuseMethod · 0.80
is_mmappedMethod · 0.80
chunk_minus_offsetMethod · 0.80
set_free_with_pinuseMethod · 0.80
cinuseMethod · 0.80

Tested by

no test coverage detected