* Allocate a block of memory with a minimum of 'size' bytes. * * @param size is the minimum size of the requested block in bytes. * @return pointer to allocated memory or NULL if no free memory was found. * * Note that the returned value must always be aligned (as defined by MEM_ALIGNMENT). */
| 204 | * Note that the returned value must always be aligned (as defined by MEM_ALIGNMENT). |
| 205 | */ |
| 206 | void * |
| 207 | mem_malloc(mem_size_t size) |
| 208 | { |
| 209 | void *ret = mem_clib_malloc(size + MEM_LIBC_STATSHELPER_SIZE); |
| 210 | if (ret == NULL) { |
| 211 | MEM_STATS_INC_LOCKED(err); |
| 212 | } else { |
| 213 | LWIP_ASSERT("malloc() must return aligned memory", LWIP_MEM_ALIGN(ret) == ret); |
| 214 | #if LWIP_STATS && MEM_STATS |
| 215 | *(mem_size_t *)ret = size; |
| 216 | ret = (u8_t *)ret + MEM_LIBC_STATSHELPER_SIZE; |
| 217 | MEM_STATS_INC_USED_LOCKED(used, size); |
| 218 | #endif |
| 219 | } |
| 220 | return ret; |
| 221 | } |
| 222 | |
| 223 | /** Put memory back on the heap |
| 224 | * |