Merge branch 'feature/tw8799_low_level_output_optimize' into 'master'

Feature/tw8799 low level output optimize

Fix a potential memory crash error in low_level_output

See merge request !224
This commit is contained in:
Wu Jian Gang
2016-11-22 11:56:35 +08:00

View File

@@ -118,37 +118,29 @@ low_level_init(struct netif *netif)
static err_t static err_t
low_level_output(struct netif *netif, struct pbuf *p) low_level_output(struct netif *netif, struct pbuf *p)
{ {
struct pbuf *q; wifi_interface_t wifi_if = tcpip_adapter_get_wifi_if(netif);
wifi_interface_t wifi_if = tcpip_adapter_get_wifi_if(netif); struct pbuf *q = p;
err_t ret;
if (wifi_if >= WIFI_IF_MAX) { if (wifi_if >= WIFI_IF_MAX) {
return ERR_IF; return ERR_IF;
} }
#if ESP_LWIP if(q->next == NULL) {
q = p; ret = esp_wifi_internal_tx(wifi_if, q->payload, q->len);
u16_t pbuf_x_len = 0; } else {
pbuf_x_len = q->len; LWIP_DEBUGF(PBUF_DEBUG, ("low_level_output: pbuf is a list, application may has bug"));
if(q->next !=NULL) q = pbuf_alloc(PBUF_RAW_TX, p->tot_len, PBUF_RAM);
{ if (q != NULL) {
//char cnt = 0; pbuf_copy(q, p);
struct pbuf *tmp = q->next; } else {
while(tmp != NULL) return ERR_MEM;
{
memcpy( (u8_t *)( (u8_t *)(q->payload) + pbuf_x_len), (u8_t *)tmp->payload , tmp->len );
pbuf_x_len += tmp->len;
//cnt++;
tmp = tmp->next;
} }
ret = esp_wifi_internal_tx(wifi_if, q->payload, q->len);
pbuf_free(q);
} }
return esp_wifi_internal_tx(wifi_if, q->payload, pbuf_x_len); return ret;
#else
for(q = p; q != NULL; q = q->next) {
esp_wifi_internal_tx(wifi_if, q->payload, q->len);
}
return ERR_OK;
#endif
} }
/** /**