MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / ztrycalloc_usable

Function ztrycalloc_usable

src/zmalloc.cpp:171–187  ·  view source on GitHub ↗

Try allocating memory and zero it, and return NULL if failed. * '*usable' is set to the usable size if non NULL. */

Source from the content-addressed store, hash-verified

169/* Try allocating memory and zero it, and return NULL if failed.
170 * '*usable' is set to the usable size if non NULL. */
171void *ztrycalloc_usable(size_t size, size_t *usable) {
172 ASSERT_NO_SIZE_OVERFLOW(size);
173 void *ptr = calloc(1, MALLOC_MIN_SIZE(size)+PREFIX_SIZE, MALLOC_LOCAL);
174 if (ptr == NULL) return NULL;
175
176#ifdef HAVE_MALLOC_SIZE
177 size = zmalloc_size(ptr);
178 update_zmalloc_stat_alloc(size);
179 if (usable) *usable = size;
180 return ptr;
181#else
182 *((size_t*)ptr) = size;
183 update_zmalloc_stat_alloc(size+PREFIX_SIZE);
184 if (usable) *usable = size;
185 return (char*)ptr+PREFIX_SIZE;
186#endif
187}
188
189/* Allocate memory and zero it or panic */
190void *zcalloc(size_t size, enum MALLOC_CLASS /*mclass*/) {

Callers 3

zcallocFunction · 0.85
ztrycallocFunction · 0.85
zcalloc_usableFunction · 0.85

Calls 2

callocFunction · 0.85
zmalloc_sizeFunction · 0.85

Tested by

no test coverage detected