[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-devel] [task #15205] memory leak in autoip.c
From: |
zhangyanjiao |
Subject: |
[lwip-devel] [task #15205] memory leak in autoip.c |
Date: |
Wed, 13 Mar 2019 02:21:09 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36 |
URL:
<https://savannah.nongnu.org/task/?15205>
Summary: memory leak in autoip.c
Project: lwIP - A Lightweight TCP/IP stack
Submitted by: anne1993
Submitted on: Wed 13 Mar 2019 06:21:07 AM UTC
Category: IPv4
Should Start On: Wed 13 Mar 2019 12:00:00 AM UTC
Should be Finished on: Wed 13 Mar 2019 12:00:00 AM UTC
Priority: 5 - Normal
Status: None
Privacy: Public
Percent Complete: 0%
Assigned to: None
Open/Closed: Open
Discussion Lock: Any
Planned Release: None
Effort: 0.00
_______________________________________________________
Details:
When I test the autoip, In find there is memory leak in autoip.c:
In autopip_start() function, mem_malloc is called to alloc memory:
autoip_start(struct netif *netif)
{
struct autoip* autoip = netif_autoip_data(netif);
if (autoip == NULL) {
/* no AutoIP client attached yet? */
autoip = (struct autoip *)mem_malloc(sizeof(struct autoip));
……
}
But in autoip_stop() function, there is no function to free this memory:
err_t
autoip_stop(struct netif *netif)
{
struct autoip* autoip = netif_autoip_data(netif);
if (autoip != NULL) {
autoip->state = AUTOIP_STATE_OFF;
if (ip4_addr_islinklocal(netif_ip4_addr(netif))) {
netif_set_addr(netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4);
}
}
return ERR_OK;
}
The correct code will be like the following:
err_t
autoip_stop(struct netif *netif)
{
struct autoip* autoip = netif_autoip_data(netif);
if (autoip != NULL) {
autoip->state = AUTOIP_STATE_OFF;
if (ip4_addr_islinklocal(netif_ip4_addr(netif))) {
netif_set_addr(netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4);
}
mem_free(autoip);
netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP, NULL);
}
return ERR_OK;
}
_______________________________________________________
Reply to this item at:
<https://savannah.nongnu.org/task/?15205>
_______________________________________________
Message sent via Savannah
https://savannah.nongnu.org/
- [lwip-devel] [task #15205] memory leak in autoip.c,
zhangyanjiao <=