* Allocate memory for a packet buffer for a given netbuf. * * @param buf the netbuf for which to allocate a packet buffer * @param size the size of the packet buffer to allocate * @return pointer to the allocated memory * NULL if no memory could be allocated */
| 104 | * NULL if no memory could be allocated |
| 105 | */ |
| 106 | void * |
| 107 | netbuf_alloc(struct netbuf *buf, u16_t size) |
| 108 | { |
| 109 | LWIP_ERROR("netbuf_alloc: invalid buf", (buf != NULL), return NULL;); |
| 110 | |
| 111 | /* Deallocate any previously allocated memory. */ |
| 112 | if (buf->p != NULL) { |
| 113 | pbuf_free(buf->p); |
| 114 | } |
| 115 | buf->p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM); |
| 116 | if (buf->p == NULL) { |
| 117 | return NULL; |
| 118 | } |
| 119 | LWIP_ASSERT("check that first pbuf can hold size", |
| 120 | (buf->p->len >= size)); |
| 121 | buf->ptr = buf->p; |
| 122 | return buf->p->payload; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Free the packet buffer included in a netbuf |
no test coverage detected