[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-users] http_client.c - heap memory overflow
From: |
Jaroslav |
Subject: |
[lwip-users] http_client.c - heap memory overflow |
Date: |
Mon, 06 Jan 2020 00:09:13 +0100 |
User-agent: |
Roundcube Webmail/1.1.12 |
Hello,
I am using LWIP 2.1.2 + FreeRTOS 10 on board TM4C1294XL. I am trying to
push measured data to a web server using http_client.c. I mannaged to
make it working based on example in
https://lists.nongnu.org/archive/html/lwip-users/2019-07/msg00001.
However, with each calling of httpc_get_file_dns usage of heap memory
increases, and after approx 500th calling the application stops working
due to heap memory overflow:
MEM HEAP:
avail: 32768
used: 31948
max: 32732
err: 561
and I am getting the following erros:
httpc_result: 7
memp_malloc: out of memory in pool TCP_PCB
mem_malloc: could not allocate 412 bytes
Here is my simplified code:
--------------------------------------------------------
#define STACKSIZE_HTTPCTASK 4096
err_t
RecvCallback(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{
char str[100];
if (p == NULL)
UARTprintf("NULL TCP packet received\n");
else
{
memcpy(&str, p->payload, p->len);
if(strstr(str, "success") == NULL)
UARTprintf("GET FAILED: %s\n", str);
}
pbuf_free(p);
tcp_close(tpcb);
return ERR_OK;
}
err_t
RecvHttpHeaderCallback(httpc_state_t *connection, void *arg, struct pbuf
*hdr, u16_t hdr_len, u32_t content_len)
{
return ERR_OK;
}
void
HttpClientResultCallback(void *arg, httpc_result_t httpc_result, u32_t
rx_content_len, u32_t srv_res, err_t err)
{
UARTprintf("httpc_result: %u\n", httpc_result);
UARTprintf("received number of bytes: %lu\n", rx_content_len);
}
static void
HttpcTask(void *pvParameters)
{
portTickType ui32LastTime;
httpc_connection_t conn_settings;
httpc_state_t *connection;
conn_settings.use_proxy = 0;
conn_settings.headers_done_fn = RecvHttpHeaderCallback;
conn_settings.result_fn = HttpClientResultCallback;
ui32LastTime = xTaskGetTickCount();
while(1)
{
httpc_get_file_dns("my.domain.com", 80, "/write.php?d=myData",
&conn_settings, RecvCallback, NULL, &connection);
vTaskDelayUntil(&ui32LastTime, g_ui32HttpcDelay / portTICK_RATE_MS);
}
}
uint32_t
HttpcTaskInit(void)
{
xTaskCreate(HttpcTask, (const portCHAR *)"Httpc",
STACKSIZE_HTTPCTASK, NULL,
tskIDLE_PRIORITY + PRIORITY_HTTPC_TASK, NULL)
return(0);
}
------------------------------------------------------------
Any idea what I am doing wrong?
Thanks
Jaroslav