MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / internal_bulk_free

Function internal_bulk_free

system/lib/dlmalloc.c:5191–5231  ·  view source on GitHub ↗

Try to free all pointers in the given array. Note: this could be made faster, by delaying consolidation, at the price of disabling some user integrity checks, We still optimize some consolidations by combining adjacent chunks before freeing, which will occur often if allocated with ialloc or the array is sorted. */

Source from the content-addressed store, hash-verified

5189 with ialloc or the array is sorted.
5190 */
5191static size_t internal_bulk_free(mstate m, void* array[], size_t nelem) {
5192 size_t unfreed = 0;
5193 if (!PREACTION(m)) {
5194 void** a;
5195 void** fence = &(array[nelem]);
5196 for (a = array; a != fence; ++a) {
5197 void* mem = *a;
5198 if (mem != 0) {
5199 mchunkptr p = mem2chunk(mem);
5200 size_t psize = chunksize(p);
5201#if FOOTERS
5202 if (get_mstate_for(p) != m) {
5203 ++unfreed;
5204 continue;
5205 }
5206#endif
5207 check_inuse_chunk(m, p);
5208 *a = 0;
5209 if (RTCHECK(ok_address(m, p) && ok_inuse(p))) {
5210 void ** b = a + 1; /* try to merge with next chunk */
5211 mchunkptr next = next_chunk(p);
5212 if (b != fence && *b == chunk2mem(next)) {
5213 size_t newsize = chunksize(next) + psize;
5214 set_inuse(m, p, newsize);
5215 *b = chunk2mem(p);
5216 }
5217 else
5218 dispose_chunk(m, p, psize);
5219 }
5220 else {
5221 CORRUPTION_ERROR_ACTION(m);
5222 break;
5223 }
5224 }
5225 }
5226 if (should_trim(m, m->topsize))
5227 sys_trim(m, 0);
5228 POSTACTION(m);
5229 }
5230 return unfreed;
5231}
5232
5233/* Traversal */
5234#if MALLOC_INSPECT_ALL

Callers 2

dlbulk_freeFunction · 0.85
mspace_bulk_freeFunction · 0.85

Calls 2

dispose_chunkFunction · 0.85
sys_trimFunction · 0.85

Tested by

no test coverage detected