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

Function dlrealloc

system/lib/dlmalloc.c:5279–5326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5277#if !ONLY_MSPACES
5278
5279void* dlrealloc(void* oldmem, size_t bytes) {
5280 void* mem = 0;
5281 if (oldmem == 0) {
5282 mem = dlmalloc(bytes);
5283 }
5284 else if (bytes >= MAX_REQUEST) {
5285 MALLOC_FAILURE_ACTION;
5286 }
5287#ifdef REALLOC_ZERO_BYTES_FREES
5288 else if (bytes == 0) {
5289 dlfree(oldmem);
5290 }
5291#endif /* REALLOC_ZERO_BYTES_FREES */
5292 else {
5293 size_t nb = request2size(bytes);
5294 mchunkptr oldp = mem2chunk(oldmem);
5295#if ! FOOTERS
5296 mstate m = gm;
5297#else /* FOOTERS */
5298 mstate m = get_mstate_for(oldp);
5299 if (!ok_magic(m)) {
5300 USAGE_ERROR_ACTION(m, oldmem);
5301 return 0;
5302 }
5303#endif /* FOOTERS */
5304 if (!PREACTION(m)) {
5305 mchunkptr newp = try_realloc_chunk(m, oldp, nb, 1);
5306 POSTACTION(m);
5307 if (newp != 0) {
5308 check_inuse_chunk(m, newp);
5309 mem = chunk2mem(newp);
5310#if __EMSCRIPTEN__
5311 /* XXX Emscripten Tracing API. */
5312 emscripten_trace_record_reallocation(oldmem, mem, bytes);
5313#endif
5314 }
5315 else {
5316 mem = internal_malloc(m, bytes);
5317 if (mem != 0) {
5318 size_t oc = chunksize(oldp) - overhead_for(oldp);
5319 memcpy(mem, oldmem, (oc < bytes)? oc : bytes);
5320 internal_free(m, oldmem);
5321 }
5322 }
5323 }
5324 }
5325 return mem;
5326}
5327
5328void* dlrealloc_in_place(void* oldmem, size_t bytes) {
5329 void* mem = 0;

Callers

nothing calls this directly

Calls 3

dlmallocFunction · 0.85
try_realloc_chunkFunction · 0.85
memcpyFunction · 0.85

Tested by

no test coverage detected