Try allocating memory, and return NULL if failed. * '*usable' is set to the usable size if non NULL. */
| 97 | /* Try allocating memory, and return NULL if failed. |
| 98 | * '*usable' is set to the usable size if non NULL. */ |
| 99 | void *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 */ |
| 118 | void *zmalloc(size_t size) { |
no test coverage detected