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-apps.git

commit d03060c37d3216c5ef85a4ed6216e3d93ab2792b
Author: gaohedong <[email protected]>
AuthorDate: Mon Nov 9 18:10:24 2026 +0800

    netutils/iperf: fix minor resource and error-report issues
    
    Log the connected socket instead of the listening one when a TCP
    server recv fails, drop the unused sockfd field, destroy thread
    attributes after use, free the traffic buffer in iperf_start() on all
    paths, and stop reporting EINTR from the stop signals as a socket error
    or a UDP client send abort.
    
    Signed-off-by: gaohedong <[email protected]>
    Assisted-by: Kiro:claude-opus-4
---
 netutils/iperf/iperf.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/netutils/iperf/iperf.c b/netutils/iperf/iperf.c
index 18adb664a..f9f4a4ece 100644
--- a/netutils/iperf/iperf.c
+++ b/netutils/iperf/iperf.c
@@ -86,7 +86,6 @@ struct iperf_ctrl_t
   uintmax_t total_len;
   uint32_t buffer_len;
   FAR uint8_t *buffer;
-  uint32_t sockfd;
 #ifdef IPERF_HAVE_NETPOLL
   struct netpoll_s netpoll;
 #endif
@@ -285,7 +284,9 @@ static int iperf_show_socket_error_reason(FAR const char 
*str, int sockfd)
 {
   int err = errno;
 
-  if (err != 0)
+  /* EINTR only comes from our own stop signals; it is not an error. */
+
+  if (err != 0 && err != EINTR)
     {
       printf("%s error, error code: %d, reason: %s\n",
              str, err, strerror(err));
@@ -472,6 +473,7 @@ static int iperf_start_report(FAR struct iperf_ctrl_t *ctrl)
 
   ret = pthread_create(&thread, &attr, (FAR void *)iperf_report_task,
                        ctrl);
+  pthread_attr_destroy(&attr);
   if (ret != 0)
     {
       printf("iperf_thread: pthread_create failed: %d, %s\n",
@@ -681,7 +683,7 @@ static int iperf_tcp_server(FAR struct iperf_ctrl_t *ctrl,
           else if (actual_recv < 0)
             {
               iperf_show_socket_error_reason("tcp server recv",
-                                             listen_socket);
+                                             sockfd);
               ctrl->finish = true;
               break;
             }
@@ -1041,7 +1043,11 @@ static int iperf_udp_client(FAR struct iperf_ctrl_t 
*ctrl,
             }
           else
             {
-              printf("udp client send abort: err=%d\n", err);
+              if (!ctrl->finish)
+                {
+                  printf("udp client send abort: err=%d\n", err);
+                }
+
               break;
             }
         }
@@ -1194,14 +1200,7 @@ static void iperf_task_traffic(FAR void *arg)
       assert(false);
     }
 
-  if (ctrl->buffer)
-    {
-      free(ctrl->buffer);
-      ctrl->buffer = NULL;
-    }
-
   printf("iperf exit\n");
-
   pthread_exit(NULL);
 }
 
@@ -1311,6 +1310,7 @@ int iperf_start(FAR struct iperf_cfg_t *cfg)
 
   ret = pthread_create(&ctrl.traffic_thread, &attr,
                        (FAR void *)iperf_task_traffic, &ctrl);
+  pthread_attr_destroy(&attr);
   if (ret != 0)
     {
       printf("iperf_task_traffic: create task failed: %d\n", ret);
@@ -1343,6 +1343,7 @@ int iperf_start(FAR struct iperf_cfg_t *cfg)
   sigaction(SIGPIPE, &oldpipe, NULL);
   sigaction(SIGUSR1, &oldusr1, NULL);
 
+  free(ctrl.buffer);
   return 0;
 }
 

Reply via email to