You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ar...@apache.org on 2022/01/05 14:01:21 UTC
[incubator-nuttx] branch master updated: net/devif: Fix the memory leak in case of netdev isn't alive
This is an automated email from the ASF dual-hosted git repository.
archer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new e27962a net/devif: Fix the memory leak in case of netdev isn't alive
e27962a is described below
commit e27962a997f8ba8ec69d670e322fc45282824477
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Sep 19 10:08:48 2021 +0800
net/devif: Fix the memory leak in case of netdev isn't alive
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
net/devif/devif_callback.c | 30 ++++++++++++++----------------
1 file changed, 14 insertions(+), 16 deletions(-)
diff --git a/net/devif/devif_callback.c b/net/devif/devif_callback.c
index 138ba05..1059533 100644
--- a/net/devif/devif_callback.c
+++ b/net/devif/devif_callback.c
@@ -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;
}