savannah-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[savannah-help-public] [sr #109655] memory leak in autoip.c


From: zhangyanjiao
Subject: [savannah-help-public] [sr #109655] memory leak in autoip.c
Date: Wed, 13 Mar 2019 00:05:25 -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/support/?109655>

                 Summary: memory leak in autoip.c
                 Project: Savannah Administration
            Submitted by: anne1993
            Submitted on: Wed 13 Mar 2019 04:05:23 AM UTC
                Category: Savannah trackers - bugs, tasks, etc.
                Priority: 5 - Normal
                Severity: 3 - Normal
                  Status: None
             Assigned to: None
        Originator Email: 
        Operating System: GNU/Linux
             Open/Closed: Open
         Discussion Lock: Any

    _______________________________________________________

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/support/?109655>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]