Try allocating memory, and return NULL if failed. * '*usable' is set to the usable size if non NULL. */
| 109 | /* Try allocating memory, and return NULL if failed. |
| 110 | * '*usable' is set to the usable size if non NULL. */ |
| 111 | void *ztrymalloc_usable(size_t size, size_t *usable) { |
| 112 | ASSERT_NO_SIZE_OVERFLOW(size); |
| 113 | void *ptr = malloc(MALLOC_MIN_SIZE(size)+PREFIX_SIZE, MALLOC_LOCAL); |
| 114 | |
| 115 | if (!ptr) return NULL; |
| 116 | #ifdef HAVE_MALLOC_SIZE |
| 117 | size = zmalloc_size(ptr); |
| 118 | update_zmalloc_stat_alloc(size); |
| 119 | if (usable) *usable = size; |
| 120 | return ptr; |
| 121 | #else |
| 122 | *((size_t*)ptr) = size; |
| 123 | update_zmalloc_stat_alloc(size+PREFIX_SIZE); |
| 124 | if (usable) *usable = size; |
| 125 | return (char*)ptr+PREFIX_SIZE; |
| 126 | #endif |
| 127 | } |
| 128 | |
| 129 | /* Allocate memory or panic */ |
| 130 | void *zmalloc(size_t size, enum MALLOC_CLASS /*mclass*/) { |
no test coverage detected