MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / realloc

Function realloc

db/memdebug.c:461–507  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

459}
460
461void *realloc(void *ptr, size_t size) {
462 struct call *c;
463 struct memblock *b;
464 struct thread_info *ti;
465 size_t was_size = 0;
466
467 /* record new place we allocated from */
468 ti = get_thread_info();
469
470 init();
471 if (in_init)
472 return dl_realloc(ptr, size);
473
474
475 /* this part is identical to free */
476 LOCK(&lk) {
477 if (ptr != NULL) {
478 /* get back to memblock */
479 b = (struct memblock *) ((intptr_t) ptr - offsetof(struct memblock, mem));
480 c = b->place_allocated;
481 c->total_allocated -= b->blocksize;
482 listc_rfl(&c->blocks, b);
483 listc_rfl(&blocks, b);
484 listc_rfl(&b->ti->blocks, b);
485 was_size = b->blocksize;
486 }
487 else
488 b = NULL;
489
490 /* do the real realloc (include the memblock portion). done under
491 lock to prevent funny math */
492 b = dl_realloc(b, offsetof(struct memblock, mem) + size);
493
494 /* readjust block size */
495 b->blocksize = size;
496
497 c = get_call();
498 b->place_allocated = c;
499 c->total_allocated += size;
500 b->ti = ti;
501 listc_abl(&c->blocks, b);
502 listc_abl(&blocks, b);
503 listc_abl(&ti->blocks, b);
504 } UNLOCK(&lk);
505
506 return b->mem;
507}
508
509char *strdup(const char *s) {
510 int sz;

Callers 15

db_generatorFunction · 0.85
read_lineFunction · 0.85
get_multi_line_statementFunction · 0.85
dumpFunction · 0.85
rheaderFunction · 0.85
dbt_rprintFunction · 0.85
dbt_rdumpFunction · 0.85
client_thdFunction · 0.85
add_testFunction · 0.85
elect_threadFunction · 0.85
kv_getFunction · 0.85
kv_get_keysFunction · 0.85

Calls 6

dl_reallocFunction · 0.85
listc_rflFunction · 0.85
get_callFunction · 0.85
listc_ablFunction · 0.85
get_thread_infoFunction · 0.70
initFunction · 0.70

Tested by 4

add_testFunction · 0.68
get_multi_line_statementFunction · 0.68
test_config_heapFunction · 0.68