fix(lwip): fix TCP pbuf memory leak

Disable TCP cache and retry function.
This commit is contained in:
Dong Heng
2018-12-04 11:35:59 +08:00
parent 98bdb57bea
commit e19f612606
4 changed files with 22 additions and 30 deletions

View File

@ -427,8 +427,10 @@ again:
return;
}
#if ESP_TCP
extern void send_from_list();
send_from_list();
#endif
#if ESP_UDP
udp_sync_proc();

View File

@ -19,32 +19,12 @@
#include "esp8266/eagle_soc.h"
#ifdef ESP_LWIP
/*
* @brief allocate an only DRAM memory block for LWIP pbuf
*
* @param s memory size
*
* @return memory block pointer
*/
void *mem_malloc_ll(size_t s)
#if MEMP_SIZE != 0
#error "MEMP_SIZE must be 0"
#else /* MEMP_SIZE != 0 */
size_t memp_malloc_get_size(size_t type)
{
void *return_addr = (void *)__builtin_return_address(0);
return _heap_caps_malloc(s, MALLOC_CAP_8BIT, return_addr, 0);
return memp_pools[type]->size;
}
void *memp_malloc_ll(size_t type)
{
extern const struct memp_desc* const memp_pools[MEMP_MAX];
uint8_t *p;
const struct memp_desc *desc = memp_pools[type];
p = (uint8_t *)mem_malloc_ll(MEMP_SIZE + MEMP_ALIGN_SIZE(desc->size));
if (p)
p += MEMP_SIZE;
return p;
}
#endif
#endif /* MEMP_SIZE != 0 */
#endif /* ESP_LWIP */

View File

@ -213,6 +213,8 @@
#define ESP_LWIP_MEM_DBG 1
#endif
size_t memp_malloc_get_size(size_t type);
/*
* @brief allocate an only DRAM memory block for LWIP pbuf
*
@ -220,7 +222,7 @@
*
* @return memory block pointer
*/
void *mem_malloc_ll(size_t s);
#define mem_malloc_ll(s) heap_caps_malloc(s, MALLOC_CAP_8BIT)
/*
* @brief allocate an only DRAM memory pool for LWIP pbuf
@ -229,7 +231,7 @@ void *mem_malloc_ll(size_t s);
*
* @return memory pool pointer
*/
void *memp_malloc_ll(size_t type);
#define memp_malloc_ll(type) heap_caps_malloc(memp_malloc_get_size(type), MALLOC_CAP_8BIT)
#endif
/**

View File

@ -34,7 +34,7 @@ void wifi_station_set_default_hostname(uint8_t* hwaddr);
#define IFNAME0 'e'
#define IFNAME1 'n'
#if ESP_TCP
typedef struct pbuf_send_list {
struct pbuf_send_list* next;
struct pbuf* p;
@ -44,8 +44,10 @@ typedef struct pbuf_send_list {
static pbuf_send_list_t* pbuf_list_head = NULL;
static int pbuf_send_list_num = 0;
#endif
static int low_level_send_cb(esp_aio_t* aio);
#if ESP_TCP
static inline bool check_pbuf_to_insert(struct pbuf* p)
{
uint8_t* buf = (uint8_t*)p->payload;
@ -172,6 +174,7 @@ void send_from_list()
}
}
}
#endif
/**
* In this function, the hardware should be initialized.
@ -213,6 +216,8 @@ static void low_level_init(struct netif* netif)
static int low_level_send_cb(esp_aio_t* aio)
{
struct pbuf* pbuf = aio->arg;
#if ESP_TCP
wifi_tx_status_t* status = (wifi_tx_status_t*) & (aio->ret);
if ((TX_STATUS_SUCCESS != status->wifi_tx_result) && check_pbuf_to_insert(pbuf)) {
@ -235,6 +240,7 @@ static int low_level_send_cb(esp_aio_t* aio)
status->wifi_tx_result, status->wifi_tx_lrc, status->wifi_tx_src, status->wifi_tx_rate));
insert_to_list(aio->fd, aio->arg);
}
#endif
pbuf_free(pbuf);
@ -350,7 +356,9 @@ static int8_t low_level_output(struct netif* netif, struct pbuf* p)
if (err != ERR_OK) {
if (err == ERR_MEM) {
#if ESP_TCP
insert_to_list(aio.fd, p);
#endif
err = ERR_OK;
}