net/devif: Fix the memory leak in case of netdev isn't alive

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2021-09-19 10:08:48 +08:00 committed by archer
parent f93c17be94
commit e27962a997

View File

@ -269,6 +269,20 @@ FAR struct devif_callback_s *
net_lock();
/* Verify that the device pointer is valid, i.e., that it still
* points to a registered network device and also that the network
* device in the UP state.
*/
if (dev && !netdev_verify(dev) && (dev->d_flags & IFF_UP) != 0)
{
/* No.. release the callback structure and fail */
devif_callback_free(NULL, NULL, list_head, list_tail);
net_unlock();
return NULL;
}
/* Allocate the callback entry from heap */
#ifdef CONFIG_NET_ALLOC_CONNS
@ -303,22 +317,6 @@ FAR struct devif_callback_s *
if (dev)
{
/* Verify that the device pointer is valid, i.e., that it still
* points to a registered network device and also that the network
* device in in the UP state.
*
* And if it does, should that device also not be in the UP state?
*/
if (!netdev_verify(dev) && (dev->d_flags & IFF_UP) != 0)
{
/* No.. release the callback structure and fail */
devif_callback_free(NULL, NULL, list_head, list_tail);
net_unlock();
return NULL;
}
ret->nxtdev = dev->d_devcb;
dev->d_devcb = ret;
}