Copilot commented on code in PR #21755:
URL: https://github.com/apache/nuttx/pull/21755#discussion_r4564228011
##########
fs/socket/accept.c:
##########
@@ -93,6 +94,15 @@ static int map_user_mem(FAR void *uaddr, size_t size, void
**p_kaddr)
}
#endif
+/****************************************************************************
+ * Name: accept4_cleanup
+ ****************************************************************************/
+
+static void accept4_cleanup(FAR void *arg)
+{
+ file_put(arg);
Review Comment:
`accept4_cleanup()` passes a `void *` directly to `file_put()`, which
obscures the expected type and makes the cleanup contract less
self-documenting. Consider casting `arg` to `FAR struct file *` inside the
function (or changing the local variable name accordingly) so the callback’s
intent and expected argument type are explicit.
##########
fs/socket/accept.c:
##########
@@ -264,6 +278,7 @@ int accept4(int sockfd, FAR struct sockaddr *addr, FAR
socklen_t *addrlen,
goto errout_with_psock;
}
+ tls_cleanup_pop(tls_get_info(), 0);
Review Comment:
`tls_get_info()` is called multiple times around the push/pop pair. To keep
the pairing clearer (and avoid accidental mismatches if this code is modified
later), consider storing the `tls_get_info()` result in a local variable and
using that for both `tls_cleanup_push()` and `tls_cleanup_pop()` calls.
##########
fs/socket/accept.c:
##########
@@ -229,6 +239,10 @@ int accept4(int sockfd, FAR struct sockaddr *addr, FAR
socklen_t *addrlen,
goto errout_with_kmap;
}
+ /* Drop the reference to the listening socket if canceled in accept */
+
+ tls_cleanup_push(tls_get_info(), accept4_cleanup, filep);
Review Comment:
`tls_get_info()` is called multiple times around the push/pop pair. To keep
the pairing clearer (and avoid accidental mismatches if this code is modified
later), consider storing the `tls_get_info()` result in a local variable and
using that for both `tls_cleanup_push()` and `tls_cleanup_pop()` calls.
##########
fs/socket/accept.c:
##########
@@ -281,6 +296,7 @@ int accept4(int sockfd, FAR struct sockaddr *addr, FAR
socklen_t *addrlen,
fs_heap_free(newsock);
errout_with_filep:
+ tls_cleanup_pop(tls_get_info(), 0);
Review Comment:
`tls_get_info()` is called multiple times around the push/pop pair. To keep
the pairing clearer (and avoid accidental mismatches if this code is modified
later), consider storing the `tls_get_info()` result in a local variable and
using that for both `tls_cleanup_push()` and `tls_cleanup_pop()` calls.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]