From e3c12e9d73678b3c5445f770c929e035ef1c4997 Mon Sep 17 00:00:00 2001
From: yinbin6 <yinbin8@huawei.com>
Date: Fri, 7 Jun 2024 11:13:08 +0800
Subject: [PATCH] EPOLL: fix coredump while event count exceed maxevents

---
 src/lstack/api/lstack_epoll.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c
index c8a2e43..28a3dd9 100644
--- a/src/lstack/api/lstack_epoll.c
+++ b/src/lstack/api/lstack_epoll.c
@@ -488,7 +488,14 @@ int32_t epoll_lwip_event_nolock(struct wakeup_poll *wakeup, struct epoll_event *
             list_del_node_null(node);
             continue;
         }
-
+        
+        if (event_num >= maxevents) {
+            /* move list head after the current node, and start traversing from this node next time */
+            list_del_node_null(&wakeup->event_list);
+            list_add_node(node, &wakeup->event_list);
+            break;
+        }
+        
         events[event_num].events = sock->events & sock->epoll_events;
         events[event_num].data = sock->ep_data;
         event_num++;
@@ -504,13 +511,6 @@ int32_t epoll_lwip_event_nolock(struct wakeup_poll *wakeup, struct epoll_event *
             list_del_node_null(node);
             sock->epoll_events = 0;
         }
-
-        if (event_num >= maxevents) {
-            /* move list head after the current node, and start traversing from this node next time */
-            list_del_node_null(&wakeup->event_list);
-            list_add_node(node, &wakeup->event_list);
-            break;
-        }
     }
 
     return event_num;
-- 
2.33.0

