fix(tcpip_adapter): Fix recv pbuf memory leak

This commit is contained in:
dongheng
2019-04-28 15:57:24 +08:00
parent b2f76cd939
commit f2a0d64277
2 changed files with 8 additions and 2 deletions

View File

@ -403,6 +403,7 @@ void ethernetif_input(struct netif* netif, struct pbuf* p)
if (netif == NULL) { if (netif == NULL) {
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: netif is NULL\n")); LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: netif is NULL\n"));
pbuf_free(p);
goto _exit; goto _exit;
} }

View File

@ -229,12 +229,12 @@ static int tcpip_adapter_recv_cb(void *index, void *buffer, uint16_t len, void *
p = os_malloc(sizeof(struct tcpip_adapter_pbuf)); p = os_malloc(sizeof(struct tcpip_adapter_pbuf));
if (!p) if (!p)
return -ENOMEM; goto no_mem;
// PBUF_RAW means payload = (char *)aio->pbuf + offset(=0) // PBUF_RAW means payload = (char *)aio->pbuf + offset(=0)
pbuf = pbuf_alloced_custom(PBUF_RAW, len, PBUF_REF, &p->pbuf, buffer, len); pbuf = pbuf_alloced_custom(PBUF_RAW, len, PBUF_REF, &p->pbuf, buffer, len);
if (!pbuf) if (!pbuf)
return -ENOMEM; goto pbuf_err;
p->pbuf.custom_free_function = tcpip_adapter_free_pbuf; p->pbuf.custom_free_function = tcpip_adapter_free_pbuf;
p->eb = (void *)eb; p->eb = (void *)eb;
@ -243,6 +243,11 @@ static int tcpip_adapter_recv_cb(void *index, void *buffer, uint16_t len, void *
ethernetif_input(netif, pbuf); ethernetif_input(netif, pbuf);
return 0; return 0;
pbuf_err:
os_free(p);
no_mem:
return -ENOMEM;
} }
/* /*