diff --git a/include/libwebsockets/lws-lwsac.h b/include/libwebsockets/lws-lwsac.h index 1f914b66a..f0584e50b 100644 --- a/include/libwebsockets/lws-lwsac.h +++ b/include/libwebsockets/lws-lwsac.h @@ -99,6 +99,24 @@ lws_list_ptr_insert(lws_list_ptr *phead, lws_list_ptr *add, LWS_VISIBLE LWS_EXTERN void * lwsac_use(struct lwsac **head, size_t ensure, size_t chunk_size); +/** + * lwsac_use - allocate / use some memory from a lwsac + * + * \param head: pointer to the lwsac list object + * \param ensure: the number of bytes we want to use, which must be zeroed + * \param chunk_size: 0, or the size of the chunk to (over)allocate if + * what we want won't fit in the current tail chunk. If + * 0, the default value of 4000 is used. If ensure is + * larger, it is used instead. + * + * Same as lwsac_use(), but \p ensure bytes of memory at the return address + * are zero'd before returning. + * + * Returns NULL if OOM. + */ +void * +lwsac_use_zeroed(struct lwsac **head, size_t ensure, size_t chunk_size); + /** * lwsac_free - deallocate all chunks in the lwsac and set head NULL * diff --git a/lib/misc/lwsac/lwsac.c b/lib/misc/lwsac/lwsac.c index f3059bbe4..d37f7ea1c 100644 --- a/lib/misc/lwsac/lwsac.c +++ b/lib/misc/lwsac/lwsac.c @@ -131,6 +131,17 @@ lwsac_use(struct lwsac **head, size_t ensure, size_t chunk_size) return (char *)(*head)->curr + ofs; } +void * +lwsac_use_zeroed(struct lwsac **head, size_t ensure, size_t chunk_size) +{ + void *r = lwsac_use(head, ensure, chunk_size); + + if (r) + memset(r, 0, ensure); + + return r; +} + void lwsac_free(struct lwsac **head) {