heap instrumentation

This commit is contained in:
Andy Green 2017-10-04 07:10:39 +08:00
parent 4e55c1c452
commit 4f99ccd6a8
24 changed files with 100 additions and 96 deletions

View file

@ -19,12 +19,12 @@ void __attribute__((weak))
{
}
void *lws_realloc(void *ptr, size_t size)
void *lws_realloc(void *ptr, size_t size, const char *reason)
{
return TEE_Realloc(ptr, size);
}
void *lws_malloc(size_t size)
void *lws_malloc(size_t size, const char *reason)
{
return TEE_Malloc(size, TEE_USER_MEM_HINT_NO_FILL_ZERO);
}
@ -34,7 +34,7 @@ void lws_free(void *p)
TEE_Free(p);
}
void *lws_zalloc(size_t size)
void *lws_zalloc(size_t size, const char *reason)
{
void *ptr = TEE_Malloc(size, TEE_USER_MEM_HINT_NO_FILL_ZERO);
if (ptr)
@ -42,41 +42,44 @@ void *lws_zalloc(size_t size)
return ptr;
}
void lws_set_allocator(void *(*cb)(void *ptr, size_t size))
void lws_set_allocator(void *(*cb)(void *ptr, size_t size, const char *reason))
{
(void)cb;
}
#else
static void *_realloc(void *ptr, size_t size)
static void *_realloc(void *ptr, size_t size, const char *reason)
{
if (size)
if (size) {
lwsl_debug("%s: size %lu: %s\n", __func__, (unsigned long)size, reason);
#if defined(LWS_PLAT_OPTEE)
return (void *)TEE_Realloc(ptr, size);
#else
return (void *)realloc(ptr, size);
#endif
else if (ptr)
}
if (ptr)
free(ptr);
return NULL;
}
void *(*_lws_realloc)(void *ptr, size_t size) = _realloc;
void *(*_lws_realloc)(void *ptr, size_t size, const char *reason) = _realloc;
void *lws_realloc(void *ptr, size_t size)
void *lws_realloc(void *ptr, size_t size, const char *reason)
{
return _lws_realloc(ptr, size);
return _lws_realloc(ptr, size, reason);
}
void *lws_zalloc(size_t size)
void *lws_zalloc(size_t size, const char *reason)
{
void *ptr = _lws_realloc(NULL, size);
void *ptr = _lws_realloc(NULL, size, reason);
if (ptr)
memset(ptr, 0, size);
return ptr;
}
void lws_set_allocator(void *(*cb)(void *ptr, size_t size))
void lws_set_allocator(void *(*cb)(void *ptr, size_t size, const char *reason))
{
_lws_realloc = cb;
}

View file

@ -696,7 +696,7 @@ lws_client_connect_via_info(struct lws_client_connect_info *i)
if (!i->context->protocol_init_done)
lws_protocol_init(i->context);
wsi = lws_zalloc(sizeof(struct lws));
wsi = lws_zalloc(sizeof(struct lws), "client wsi");
if (wsi == NULL)
goto bail;
@ -760,7 +760,7 @@ lws_client_connect_via_info(struct lws_client_connect_info *i)
* things pointed to have gone out of scope.
*/
wsi->u.hdr.stash = lws_malloc(sizeof(*wsi->u.hdr.stash));
wsi->u.hdr.stash = lws_malloc(sizeof(*wsi->u.hdr.stash), "client stash");
if (!wsi->u.hdr.stash) {
lwsl_err("%s: OOM\n", __func__);
goto bail;

View file

@ -1057,7 +1057,7 @@ check_accept:
if (!n)
n = context->pt_serv_buf_size;
n += LWS_PRE;
wsi->u.ws.rx_ubuf = lws_malloc(n + 4 /* 0x0000ffff zlib */);
wsi->u.ws.rx_ubuf = lws_malloc(n + 4 /* 0x0000ffff zlib */, "client frame buffer");
if (!wsi->u.ws.rx_ubuf) {
lwsl_err("Out of Mem allocating rx buffer %d\n", n);
cce = "HS: OOM";

View file

@ -59,7 +59,7 @@ lws_protocol_vh_priv_zalloc(struct lws_vhost *vhost,
/* allocate the vh priv array only on demand */
if (!vhost->protocol_vh_privs) {
vhost->protocol_vh_privs = (void **)lws_zalloc(
vhost->count_protocols * sizeof(void *));
vhost->count_protocols * sizeof(void *), "protocol_vh_privs");
if (!vhost->protocol_vh_privs)
return NULL;
}
@ -77,7 +77,7 @@ lws_protocol_vh_priv_zalloc(struct lws_vhost *vhost,
return NULL;
}
vhost->protocol_vh_privs[n] = lws_zalloc(size);
vhost->protocol_vh_privs[n] = lws_zalloc(size, "vh priv");
return vhost->protocol_vh_privs[n];
}
@ -456,7 +456,7 @@ LWS_VISIBLE struct lws_vhost *
lws_create_vhost(struct lws_context *context,
struct lws_context_creation_info *info)
{
struct lws_vhost *vh = lws_zalloc(sizeof(*vh)),
struct lws_vhost *vh = lws_zalloc(sizeof(*vh), "create vhost"),
**vh1 = &context->vhost_list;
const struct lws_http_mount *mounts;
const struct lws_protocol_vhost_options *pvo;
@ -516,7 +516,7 @@ lws_create_vhost(struct lws_context *context,
*/
lwsp = lws_zalloc(sizeof(struct lws_protocols) *
(vh->count_protocols +
context->plugin_protocol_count + 1));
context->plugin_protocol_count + 1), "vhost-specific plugin table");
if (!lwsp) {
lwsl_err("OOM\n");
return NULL;
@ -568,7 +568,7 @@ lws_create_vhost(struct lws_context *context,
}
vh->same_vh_protocol_list = (struct lws **)
lws_zalloc(sizeof(struct lws *) * vh->count_protocols);
lws_zalloc(sizeof(struct lws *) * vh->count_protocols, "same vh list");
vh->mount_list = info->mounts;
@ -621,7 +621,7 @@ lws_create_vhost(struct lws_context *context,
*/
vh->extensions = lws_zalloc(sizeof(struct lws_extension) *
(m +
context->plugin_extension_count + 1));
context->plugin_extension_count + 1), "extensions");
if (!vh->extensions)
return NULL;
@ -794,7 +794,7 @@ lws_create_context(struct lws_context_creation_info *info)
if (lws_plat_context_early_init())
return NULL;
context = lws_zalloc(sizeof(struct lws_context));
context = lws_zalloc(sizeof(struct lws_context), "context");
if (!context) {
lwsl_err("No memory for websocket context\n");
return NULL;
@ -908,7 +908,7 @@ lws_create_context(struct lws_context_creation_info *info)
* and header data pool
*/
for (n = 0; n < context->count_threads; n++) {
context->pt[n].serv_buf = lws_zalloc(context->pt_serv_buf_size);
context->pt[n].serv_buf = lws_zalloc(context->pt_serv_buf_size, "pt_serv_buf");
if (!context->pt[n].serv_buf) {
lwsl_err("OOM\n");
return NULL;
@ -919,12 +919,12 @@ lws_create_context(struct lws_context_creation_info *info)
#endif
context->pt[n].tid = n;
context->pt[n].http_header_data = lws_malloc(context->max_http_header_data *
context->max_http_header_pool);
context->max_http_header_pool, "context ah hdr data");
if (!context->pt[n].http_header_data)
goto bail;
context->pt[n].ah_pool = lws_zalloc(sizeof(struct allocated_headers) *
context->max_http_header_pool);
context->max_http_header_pool, "context ah hdr pool");
for (m = 0; m < context->max_http_header_pool; m++)
context->pt[n].ah_pool[m].data =
(char *)context->pt[n].http_header_data +
@ -988,7 +988,7 @@ lws_create_context(struct lws_context_creation_info *info)
context->pl_hash_elements =
(context->count_threads * context->fd_limit_per_thread) / 16;
context->pl_hash_table = lws_zalloc(sizeof(struct lws_peer *) *
context->pl_hash_elements);
context->pl_hash_elements, "peer limits hash table");
context->ip_limit_ah = info->ip_limit_ah;
context->ip_limit_wsi = info->ip_limit_wsi;
#endif
@ -1010,7 +1010,7 @@ lws_create_context(struct lws_context_creation_info *info)
context->max_http_header_pool);
n = sizeof(struct lws_pollfd) * context->count_threads *
context->fd_limit_per_thread;
context->pt[0].fds = lws_zalloc(n);
context->pt[0].fds = lws_zalloc(n, "fds table");
if (context->pt[0].fds == NULL) {
lwsl_err("OOM allocating %d fds\n", context->max_fds);
goto bail;
@ -1362,7 +1362,7 @@ lws_check_deferred_free(struct lws_context *context, int force)
LWS_VISIBLE void
lws_vhost_destroy(struct lws_vhost *vh)
{
struct lws_deferred_free *df = malloc(sizeof(*df));
struct lws_deferred_free *df = lws_malloc(sizeof(*df), "deferred free");
if (!df)
return;

View file

@ -129,7 +129,7 @@ lws_extension_callback_pm_deflate(struct lws_context *context,
}
/* fill in **user */
priv = lws_zalloc(sizeof(*priv));
priv = lws_zalloc(sizeof(*priv), "pmd priv");
*((void **)user) = priv;
lwsl_ext("%s: LWS_EXT_CB_*CONSTRUCT\n", __func__);
memset(priv, 0, sizeof(*priv));
@ -193,7 +193,7 @@ lws_extension_callback_pm_deflate(struct lws_context *context,
priv->rx_init = 1;
if (!priv->buf_rx_inflated)
priv->buf_rx_inflated = lws_malloc(LWS_PRE + 7 + 5 +
(1 << priv->args[PMD_RX_BUF_PWR2]));
(1 << priv->args[PMD_RX_BUF_PWR2]), "pmd rx inflate buf");
if (!priv->buf_rx_inflated) {
lwsl_err("%s: OOM\n", __func__);
return -1;
@ -343,7 +343,7 @@ lws_extension_callback_pm_deflate(struct lws_context *context,
priv->tx_init = 1;
if (!priv->buf_tx_deflated)
priv->buf_tx_deflated = lws_malloc(LWS_PRE + 7 + 5 +
(1 << priv->args[PMD_TX_BUF_PWR2]));
(1 << priv->args[PMD_TX_BUF_PWR2]), "pmd tx deflate buf");
if (!priv->buf_tx_deflated) {
lwsl_err("%s: OOM\n", __func__);
return -1;

View file

@ -340,7 +340,7 @@ lws_fops_zip_open(const struct lws_plat_file_ops *fops, const char *vfs_path,
* will come pointing at "/index.html"
*/
priv = lws_zalloc(sizeof(*priv));
priv = lws_zalloc(sizeof(*priv), "fops_zip priv");
if (!priv)
return NULL;

View file

@ -84,7 +84,7 @@ getifaddrs2(struct ifaddrs **ifap, int af, int siocgifconf, int siocgifflags,
buf_size = 8192;
for (;;) {
buf = lws_zalloc(buf_size);
buf = lws_zalloc(buf_size, "getifaddrs2");
if (buf == NULL) {
ret = ENOMEM;
goto error_out;
@ -136,7 +136,7 @@ getifaddrs2(struct ifaddrs **ifap, int af, int siocgifconf, int siocgifflags,
goto error_out;
}
*end = lws_malloc(sizeof(**end));
*end = lws_malloc(sizeof(**end), "getifaddrs");
(*end)->ifa_next = NULL;
(*end)->ifa_name = strdup(ifr->ifr_name);
@ -149,12 +149,12 @@ getifaddrs2(struct ifaddrs **ifap, int af, int siocgifconf, int siocgifflags,
/* fix these when we actually need them */
if (ifreq.ifr_flags & IFF_BROADCAST) {
(*end)->ifa_broadaddr =
lws_malloc(sizeof(ifr->ifr_broadaddr));
lws_malloc(sizeof(ifr->ifr_broadaddr), "getifaddrs");
memcpy((*end)->ifa_broadaddr, &ifr->ifr_broadaddr,
sizeof(ifr->ifr_broadaddr));
} else if (ifreq.ifr_flags & IFF_POINTOPOINT) {
(*end)->ifa_dstaddr =
lws_malloc(sizeof(ifr->ifr_dstaddr));
lws_malloc(sizeof(ifr->ifr_dstaddr), "getifaddrs");
memcpy((*end)->ifa_dstaddr, &ifr->ifr_dstaddr,
sizeof(ifr->ifr_dstaddr));
} else

View file

@ -284,7 +284,7 @@ lws_hpack_add_dynamic_header(struct lws *wsi, int token, char *arg, int len)
dyn = wsi->u.http2.hpack_dyn_table;
if (!dyn) {
dyn = lws_zalloc(sizeof(*dyn));
dyn = lws_zalloc(sizeof(*dyn), "hpack dyn");
if (!dyn)
return 1;
wsi->u.http2.hpack_dyn_table = dyn;

View file

@ -189,7 +189,7 @@ lws_uv_initloop(struct lws_context *context, uv_loop_t *loop, int tsi)
if (!pt->io_loop_uv) {
if (!loop) {
loop = lws_malloc(sizeof(*loop));
loop = lws_malloc(sizeof(*loop), "libuv loop");
if (!loop) {
lwsl_err("OOM\n");
return -1;
@ -618,7 +618,7 @@ lws_plat_plugins_init(struct lws_context *context, const char * const *d)
goto skip;
}
plugin = lws_malloc(sizeof(*plugin));
plugin = lws_malloc(sizeof(*plugin), "plugin");
if (!plugin) {
uv_dlclose(&lib);
lwsl_err("OOM\n");

View file

@ -1529,7 +1529,7 @@ lws_ensure_user_space(struct lws *wsi)
/* allocate the per-connection user memory (if any) */
if (wsi->protocol->per_session_data_size && !wsi->user_space) {
wsi->user_space = lws_zalloc(wsi->protocol->per_session_data_size);
wsi->user_space = lws_zalloc(wsi->protocol->per_session_data_size, "user space");
if (wsi->user_space == NULL) {
lwsl_err("%s: OOM\n", __func__);
return 1;
@ -2171,7 +2171,7 @@ lws_get_addr_scope(const char *ipaddr)
{
if (addrs)
free(addrs);
addrs = (IP_ADAPTER_ADDRESSES *) malloc(size);
addrs = (IP_ADAPTER_ADDRESSES *)malloc(size);
} else
{
if (addrs)
@ -2452,7 +2452,7 @@ lws_create_basic_wsi(struct lws_context *context, int tsi)
return NULL;
}
new_wsi = lws_zalloc(sizeof(struct lws));
new_wsi = lws_zalloc(sizeof(struct lws), "new wsi");
if (new_wsi == NULL) {
lwsl_err("Out of memory for new connection\n");
return NULL;
@ -2499,7 +2499,7 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, int script_uri_path_len
* give the master wsi a cgi struct
*/
wsi->cgi = lws_zalloc(sizeof(*wsi->cgi));
wsi->cgi = lws_zalloc(sizeof(*wsi->cgi), "new cgi");
if (!wsi->cgi) {
lwsl_err("%s: OOM\n", __func__);
return -1;
@ -2902,7 +2902,7 @@ lws_cgi_write_split_stdout_headers(struct lws *wsi)
if (!wsi->cgi->headers_buf) {
/* if we don't already have a headers buf, cook one up */
n = 2048;
wsi->cgi->headers_buf = malloc(n);
wsi->cgi->headers_buf = lws_malloc(n, "cgi hdr buf");
if (!wsi->cgi->headers_buf) {
lwsl_err("OOM\n");
return -1;
@ -3799,7 +3799,7 @@ lws_stats_atomic_max(struct lws_context * context,
LWS_VISIBLE LWS_EXTERN struct lws_ring *
lws_ring_create(size_t element_len, size_t count, void (*destroy_element)(void *))
{
struct lws_ring *ring = lws_malloc(sizeof(*ring));
struct lws_ring *ring = lws_malloc(sizeof(*ring), "ring create");
if (!ring)
return NULL;
@ -3810,7 +3810,7 @@ lws_ring_create(size_t element_len, size_t count, void (*destroy_element)(void *
ring->oldest_tail = 0;
ring->destroy_element = destroy_element;
ring->buf = lws_malloc(ring->buflen);
ring->buf = lws_malloc(ring->buflen, "ring buf");
if (!ring->buf) {
lws_free(ring);

View file

@ -5030,7 +5030,7 @@ lws_read(struct lws *wsi, unsigned char *buf, lws_filepos_t len);
* Allows you to replace the allocator (and deallocator) used by lws
*/
LWS_VISIBLE LWS_EXTERN void
lws_set_allocator(void *(*realloc)(void *ptr, size_t size));
lws_set_allocator(void *(*realloc)(void *ptr, size_t size, const char *reason));
///@}
/** \defgroup wsstatus Websocket status APIs

View file

@ -465,7 +465,7 @@ _lws_plat_file_open(const struct lws_plat_file_ops *fops, const char *filename,
if (fstat(ret, &stat_buf) < 0)
goto bail;
fop_fd = malloc(sizeof(*fop_fd));
fop_fd = lws_malloc(sizeof(*fop_fd), "fops open");
if (!fop_fd)
goto bail;
@ -489,7 +489,7 @@ _lws_plat_file_close(lws_fop_fd_t *fops_fd)
{
int fd = (*fops_fd)->fd;
free(*fops_fd);
lws_free(*fops_fd);
*fops_fd = NULL;
return close(fd);
@ -542,7 +542,7 @@ lws_plat_init(struct lws_context *context,
{
/* master context has the global fd lookup array */
context->lws_lookup = lws_zalloc(sizeof(struct lws *) *
context->max_fds);
context->max_fds, "esp32 lws_lookup");
if (context->lws_lookup == NULL) {
lwsl_err("OOM on lws_lookup array for %d connections\n",
context->max_fds);
@ -843,7 +843,8 @@ next:
}
if (!p) { /* did not find */
char temp[8];
p = malloc(sizeof(*p));
p = lws_malloc(sizeof(*p), "group");
if (!p)
continue;
strncpy(p->host, r->host, sizeof(p->host) - 1);
@ -892,7 +893,7 @@ next:
*p1 = p->next;
lws_group_member_event_call(LWS_SYSTEM_GROUP_MEMBER_REMOVE, p);
free(p);
lws_free(p);
continue;
}
p1 = &(*p1)->next;
@ -1153,8 +1154,8 @@ esp_err_t lws_esp32_event_passthru(void *ctx, system_event_t *event)
mdns_set_instance(lws_esp32.mdns, lws_esp32.group);
mdns_service_add(lws_esp32.mdns, "_lwsgrmem", "_tcp", 443);
if (txta[0])
free(txta[0]);
txta[0] = malloc(32 * ARRAY_SIZE(txta));
lws_free(txta[0]);
txta[0] = lws_malloc(32 * ARRAY_SIZE(txta), "group");
if (!txta[0]) {
lwsl_notice("mdns OOM\n");
break;
@ -1182,7 +1183,7 @@ esp_err_t lws_esp32_event_passthru(void *ctx, system_event_t *event)
}
if (!mem) {
struct lws_group_member *mem = malloc(sizeof(*mem));
struct lws_group_member *mem = lws_malloc(sizeof(*mem), "group");
if (mem) {
mem->last_seen = ~(uint64_t)0;
strcpy(mem->model, lws_esp32.model);

View file

@ -231,7 +231,7 @@ esp8266_create_tcp_listen_socket(struct lws_vhost *vh)
if (n < 0)
return NULL;
conn = lws_zalloc(sizeof *conn);
conn = lws_zalloc(sizeof *conn, "listen skt");
if (!conn)
return NULL;
@ -646,7 +646,7 @@ lws_plat_init(struct lws_context *context,
/* master context has the global fd lookup array */
context->connpool = lws_zalloc(sizeof(struct espconn *) *
context->max_fds * 2);
context->max_fds * 2, "connpool");
if (context->connpool == NULL) {
lwsl_err("OOM on lws_lookup array for %d connections\n",
context->max_fds);

View file

@ -310,7 +310,7 @@ lws_plat_init(struct lws_context *context,
{
/* master context has the global fd lookup array */
context->lws_lookup = lws_zalloc(sizeof(struct lws *) *
context->max_fds);
context->max_fds, "lws_lookup");
if (context->lws_lookup == NULL) {
lwsl_err("OOM on lws_lookup array for %d connections\n",
context->max_fds);

View file

@ -437,7 +437,7 @@ lws_plat_plugins_init(struct lws_context * context, const char * const *d)
goto skip;
}
plugin = lws_malloc(sizeof(*plugin));
plugin = lws_malloc(sizeof(*plugin), "plugin");
if (!plugin) {
lwsl_err("OOM\n");
goto bail;
@ -798,7 +798,7 @@ lws_plat_init(struct lws_context *context,
/* master context has the global fd lookup array */
context->lws_lookup = lws_zalloc(sizeof(struct lws *) *
context->max_fds);
context->max_fds, "lws_lookup");
if (context->lws_lookup == NULL) {
lwsl_err("OOM on lws_lookup array for %d connections\n",
context->max_fds);

View file

@ -499,7 +499,7 @@ lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt)
DWORD bufferlen = cnt;
BOOL ok = FALSE;
buffer = lws_malloc(bufferlen * 2);
buffer = lws_malloc(bufferlen * 2, "inet_ntop");
if (!buffer) {
lwsl_err("Out of memory\n");
return NULL;
@ -545,7 +545,7 @@ lws_plat_inet_pton(int af, const char *src, void *dst)
DWORD bufferlen = strlen(src) + 1;
BOOL ok = FALSE;
buffer = lws_malloc(bufferlen * 2);
buffer = lws_malloc(bufferlen * 2, "inet_pton");
if (!buffer) {
lwsl_err("Out of memory\n");
return -1;
@ -699,7 +699,7 @@ lws_plat_init(struct lws_context *context,
for (i = 0; i < FD_HASHTABLE_MODULUS; i++) {
context->fd_hashtable[i].wsi =
lws_zalloc(sizeof(struct lws*) * context->max_fds);
lws_zalloc(sizeof(struct lws*) * context->max_fds, "win hashtable");
if (!context->fd_hashtable[i].wsi)
return -1;
@ -707,7 +707,7 @@ lws_plat_init(struct lws_context *context,
while (n--) {
pt->events = lws_malloc(sizeof(WSAEVENT) *
(context->fd_limit_per_thread + 1));
(context->fd_limit_per_thread + 1), "event table");
if (pt->events == NULL) {
lwsl_err("Unable to allocate events array for %d connections\n",
context->fd_limit_per_thread + 1);

View file

@ -217,7 +217,7 @@ handle_truncated_send:
lws_free(wsi->trunc_alloc);
wsi->trunc_alloc_len = real_len - n;
wsi->trunc_alloc = lws_malloc(real_len - n);
wsi->trunc_alloc = lws_malloc(real_len - n, "truncated send alloc");
if (!wsi->trunc_alloc) {
lwsl_err("truncated send: unable to malloc %lu\n",
(unsigned long)(real_len - n));

View file

@ -2265,19 +2265,19 @@ lws_find_mount(struct lws *wsi, const char *uri_ptr, int uri_len);
* custom allocator
*/
LWS_EXTERN void *
lws_realloc(void *ptr, size_t size);
lws_realloc(void *ptr, size_t size, const char *reason);
LWS_EXTERN void * LWS_WARN_UNUSED_RESULT
lws_zalloc(size_t size);
lws_zalloc(size_t size, const char *reason);
#ifdef LWS_PLAT_OPTEE
void *lws_malloc(size_t size);
void *lws_malloc(size_t size, const char *reason);
void lws_free(void *p);
#define lws_free_set_NULL(P) do { lws_free(P); (P) = NULL; } while(0)
#else
#define lws_malloc(S) lws_realloc(NULL, S)
#define lws_free(P) lws_realloc(P, 0)
#define lws_free_set_NULL(P) do { lws_realloc(P, 0); (P) = NULL; } while(0)
#define lws_malloc(S, R) lws_realloc(NULL, S, R)
#define lws_free(P) lws_realloc(P, 0, "lws_free")
#define lws_free_set_NULL(P) do { lws_realloc(P, 0, "free"); (P) = NULL; } while(0)
#endif
const struct lws_plat_file_ops *

View file

@ -4,7 +4,7 @@
LWS_EXTERN struct lws_rewrite *
lws_rewrite_create(struct lws *wsi, hubbub_callback_t cb, const char *from, const char *to)
{
struct lws_rewrite *r = lws_malloc(sizeof(*r));
struct lws_rewrite *r = lws_malloc(sizeof(*r), "rewrite");
if (!r) {
lwsl_err("OOM\n");

View file

@ -170,7 +170,7 @@ lws_context_init_server(struct lws_context_creation_info *info,
vhost->listen_port = info->port;
vhost->iface = info->iface;
wsi = lws_zalloc(sizeof(struct lws));
wsi = lws_zalloc(sizeof(struct lws), "listen wsi");
if (wsi == NULL) {
lwsl_err("Out of mem\n");
goto bail;
@ -752,7 +752,7 @@ lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int meth)
if (wsi->access_log_pending)
lws_access_log(wsi);
wsi->access_log.header_log = lws_malloc(l);
wsi->access_log.header_log = lws_malloc(l, "access log");
if (wsi->access_log.header_log) {
tmp = localtime(&t);
@ -774,7 +774,7 @@ lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int meth)
l = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_USER_AGENT);
if (l) {
wsi->access_log.user_agent = lws_malloc(l + 2);
wsi->access_log.user_agent = lws_malloc(l + 2, "access log");
if (!wsi->access_log.user_agent) {
lwsl_err("OOM getting user agent\n");
lws_free_set_NULL(wsi->access_log.header_log);
@ -790,7 +790,7 @@ lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int meth)
}
l = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_REFERER);
if (l) {
wsi->access_log.referrer = lws_malloc(l + 2);
wsi->access_log.referrer = lws_malloc(l + 2, "referrer");
if (!wsi->access_log.referrer) {
lwsl_err("OOM getting user agent\n");
lws_free_set_NULL(wsi->access_log.user_agent);
@ -1340,7 +1340,7 @@ lws_server_init_wsi_for_ws(struct lws *wsi)
if (!n)
n = wsi->context->pt_serv_buf_size;
n += LWS_PRE;
wsi->u.ws.rx_ubuf = lws_malloc(n + 4 /* 0x0000ffff zlib */);
wsi->u.ws.rx_ubuf = lws_malloc(n + 4 /* 0x0000ffff zlib */, "rx_ubuf");
if (!wsi->u.ws.rx_ubuf) {
lwsl_err("Out of Mem allocating rx buffer %d\n", n);
return 1;
@ -1871,7 +1871,7 @@ lws_get_or_create_peer(struct lws_vhost *vhost, lws_sockfd_type sockfd)
lwsl_info("%s: creating new peer\n", __func__);
peer = lws_zalloc(sizeof(*peer));
peer = lws_zalloc(sizeof(*peer), "peer");
if (!peer) {
lws_context_unlock(context); /* === */
return NULL;
@ -2046,7 +2046,7 @@ lws_create_new_server_wsi(struct lws_vhost *vhost)
return NULL;
}
new_wsi = lws_zalloc(sizeof(struct lws));
new_wsi = lws_zalloc(sizeof(struct lws), "new server wsi");
if (new_wsi == NULL) {
lwsl_err("Out of memory for new connection\n");
return NULL;
@ -2453,7 +2453,7 @@ adopt_socket_readbuf(struct lws *wsi, const char *readbuf, size_t len)
* later successful lws_header_table_attach() will apply the
* below to the rx buffer (via lws_header_table_reset()).
*/
wsi->u.hdr.preamble_rx = lws_malloc(len);
wsi->u.hdr.preamble_rx = lws_malloc(len, "preamble_rx");
if (!wsi->u.hdr.preamble_rx) {
lwsl_err("OOM\n");
goto bail;
@ -3178,7 +3178,7 @@ static struct lws_urldecode_stateful *
lws_urldecode_s_create(struct lws *wsi, char *out, int out_len, void *data,
lws_urldecode_stateful_cb output)
{
struct lws_urldecode_stateful *s = lws_zalloc(sizeof(*s));
struct lws_urldecode_stateful *s = lws_zalloc(sizeof(*s), "stateful urldecode");
char buf[200], *p;
int m = 0;
@ -3566,7 +3566,7 @@ lws_spa_create(struct lws *wsi, const char * const *param_names,
int count_params, int max_storage,
lws_spa_fileupload_cb opt_cb, void *opt_data)
{
struct lws_spa *spa = lws_zalloc(sizeof(*spa));
struct lws_spa *spa = lws_zalloc(sizeof(*spa), "spa");
if (!spa)
return NULL;
@ -3577,12 +3577,12 @@ lws_spa_create(struct lws *wsi, const char * const *param_names,
spa->opt_cb = opt_cb;
spa->opt_data = opt_data;
spa->storage = lws_malloc(max_storage);
spa->storage = lws_malloc(max_storage, "spa");
if (!spa->storage)
goto bail2;
spa->end = spa->storage + max_storage - 1;
spa->params = lws_zalloc(sizeof(char *) * count_params);
spa->params = lws_zalloc(sizeof(char *) * count_params, "spa params");
if (!spa->params)
goto bail3;
@ -3591,7 +3591,7 @@ lws_spa_create(struct lws *wsi, const char * const *param_names,
if (!spa->s)
goto bail4;
spa->param_length = lws_zalloc(sizeof(int) * count_params);
spa->param_length = lws_zalloc(sizeof(int) * count_params, "spa param len");
if (!spa->param_length)
goto bail5;

View file

@ -73,7 +73,7 @@ lws_handle_POLLOUT_event(struct lws *wsi, struct lws_pollfd *pollfd)
int write_type = LWS_WRITE_PONG;
struct lws_tokens eff_buf;
#ifdef LWS_WITH_HTTP2
struct lws *wsi2;
struct lws *wsi2, *wsi2a;
#endif
int ret, m, n;
@ -511,8 +511,7 @@ int lws_rxflow_cache(struct lws *wsi, unsigned char *buf, int n, int len)
/* a new rxflow, buffer it and warn caller */
lwsl_info("new rxflow input buffer len %d\n", len - n);
wsi->rxflow_buffer = lws_malloc(len - n);
wsi->rxflow_buffer = lws_malloc(len - n, "rxflow buf");
if (!wsi->rxflow_buffer)
return -1;

View file

@ -208,7 +208,7 @@ uv_timeout_cb_email(uv_timer_t *w
LWS_VISIBLE LWS_EXTERN int
lws_email_init(struct lws_email *email, uv_loop_t *loop, int max_content)
{
email->content = lws_malloc(max_content);
email->content = lws_malloc(max_content, "email content");
if (!email->content)
return 1;

View file

@ -143,6 +143,7 @@ void lws_http2_configure_if_upgraded(struct lws *wsi)
/* http2 union member has http union struct at start */
wsi->u.http.ah = ah;
lws_http2_init(&wsi->u.http2.peer_settings);
lws_http2_init(&wsi->u.http2.my_settings);

View file

@ -40,7 +40,7 @@ int lws_alloc_vfs_file(struct lws_context *context, const char *filename, uint8_
len = lws_vfs_get_length(fops_fd);
*buf = malloc((size_t)len);
*buf = lws_malloc((size_t)len, "lws_alloc_vfs_file");
if (!*buf)
goto bail;
@ -68,13 +68,13 @@ int alloc_file(struct lws_context *context, const char *filename, uint8_t **buf,
n = 1;
goto bail;
}
*buf = malloc(s);
*buf = lws_malloc(s, "alloc_file");
if (!*buf) {
n = 2;
goto bail;
}
if (nvs_get_blob(nvh, filename, (char *)*buf, &s) != ESP_OK) {
free(*buf);
lws_free(*buf);
n = 1;
goto bail;
}
@ -116,14 +116,14 @@ int alloc_file(struct lws_context *context, const char *filename, uint8_t **buf,
goto bail;
}
*buf = malloc(s);
*buf = lws_malloc(s, "alloc_file");
if (!*buf) {
n = 2;
goto bail;
}
if (fread(*buf, s, 1, f) != 1) {
free(*buf);
lws_free(*buf);
n = 1;
goto bail;
}
@ -186,7 +186,7 @@ int alloc_pem_to_der_file(struct lws_context *context, const char *filename, uin
return 0;
bail:
free(pem);
lws_free(pem);
return 4;
}