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

Function ztrymalloc_usable

app/redis-6.2.6/src/zmalloc.c:99–115  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

97/* Try allocating memory, and return NULL if failed.
98 * '*usable' is set to the usable size if non NULL. */
99void *ztrymalloc_usable(size_t size, size_t *usable) {
100 ASSERT_NO_SIZE_OVERFLOW(size);
101 void *ptr = malloc(MALLOC_MIN_SIZE(size)+PREFIX_SIZE);
102
103 if (!ptr) return NULL;
104#ifdef HAVE_MALLOC_SIZE
105 size = zmalloc_size(ptr);
106 update_zmalloc_stat_alloc(size);
107 if (usable) *usable = size;
108 return ptr;
109#else
110 *((size_t*)ptr) = size;
111 update_zmalloc_stat_alloc(size+PREFIX_SIZE);
112 if (usable) *usable = size;
113 return (char*)ptr+PREFIX_SIZE;
114#endif
115}
116
117/* Allocate memory or panic */
118void *zmalloc(size_t size) {

Callers 4

zmallocFunction · 0.85
ztrymallocFunction · 0.85
zmalloc_usableFunction · 0.85
ztryrealloc_usableFunction · 0.85

Calls 2

mallocFunction · 0.85
zmalloc_sizeFunction · 0.85

Tested by

no test coverage detected