This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new df690f75226 net/pkt: Free the read-ahead queues in pkt_free().
df690f75226 is described below
commit df690f752264fb353e3dae84512214fd512fcc62
Author: Marco Casaroli <[email protected]>
AuthorDate: Sun Nov 8 09:44:34 2026 +0100
net/pkt: Free the read-ahead queues in pkt_free().
pkt_close() freed the read-ahead and error-ahead queues before the
connection left the active list. The input path can still queue frames
on the connection after that point:
- With CONFIG_NET_PKT_WRITE_BUFFERS, pkt_close() waits for the write
queue to drain with the device unlocked. A frame that comes in during
this wait is queued, for example a sent frame that comes back on lo.
- A frame can also come in between conn_dev_unlock() and pkt_free().
pkt_free() then released the connection with these IOBs still queued,
and nothing freed them.
Free the queues in pkt_free() after dq_rem(), with the connection list
locked, as can_conn_uninit(), icmp_free() and udp_free() do. pkt_in_()
queues frames with the same lock held, so no frame can come in after
this point.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
net/pkt/pkt_conn.c | 10 ++++++++++
net/pkt/pkt_sockif.c | 8 --------
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/net/pkt/pkt_conn.c b/net/pkt/pkt_conn.c
index 912284387d4..e1bda1c23f6 100644
--- a/net/pkt/pkt_conn.c
+++ b/net/pkt/pkt_conn.c
@@ -137,6 +137,16 @@ void pkt_free(FAR struct pkt_conn_s *conn)
conn_uninit(&conn->sconn);
+ /* Free the read-ahead data. pkt_in_() queues frames with the list
+ * locked, so no new frame can come in after dq_rem().
+ */
+
+ iob_free_queue(&conn->readahead);
+
+#ifdef CONFIG_NET_TIMESTAMP
+ iob_free_queue(&conn->errahead);
+#endif
+
#ifdef CONFIG_NET_PKT_WRITE_BUFFERS
/* Free the write queue */
diff --git a/net/pkt/pkt_sockif.c b/net/pkt/pkt_sockif.c
index 5643c01ddd5..436c74895ac 100644
--- a/net/pkt/pkt_sockif.c
+++ b/net/pkt/pkt_sockif.c
@@ -367,14 +367,6 @@ static int pkt_close(FAR struct socket *psock)
{
conn_dev_lock(&conn->sconn, dev);
- /* Yes... free any read-ahead data */
-
- iob_free_queue(&conn->readahead);
-
-#ifdef CONFIG_NET_TIMESTAMP
- iob_free_queue(&conn->errahead);
-#endif
-
#ifdef CONFIG_NET_PKT_WRITE_BUFFERS
/* Free write buffer callback. */