MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ztrycalloc_usable

Function ztrycalloc_usable

app/redis-6.2.6/src/zmalloc.c:159–175  ·  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

157/* Try allocating memory and zero it, and return NULL if failed.
158 * '*usable' is set to the usable size if non NULL. */
159void *ztrycalloc_usable(size_t size, size_t *usable) {
160 ASSERT_NO_SIZE_OVERFLOW(size);
161 void *ptr = calloc(1, MALLOC_MIN_SIZE(size)+PREFIX_SIZE);
162 if (ptr == NULL) return NULL;
163
164#ifdef HAVE_MALLOC_SIZE
165 size = zmalloc_size(ptr);
166 update_zmalloc_stat_alloc(size);
167 if (usable) *usable = size;
168 return ptr;
169#else
170 *((size_t*)ptr) = size;
171 update_zmalloc_stat_alloc(size+PREFIX_SIZE);
172 if (usable) *usable = size;
173 return (char*)ptr+PREFIX_SIZE;
174#endif
175}
176
177/* Allocate memory and zero it or panic */
178void *zcalloc(size_t size) {

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